X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FRatio.hs;h=22f3abeeeff8661ee1dc5a620db4d98e9abc1fff;hb=176a386c7803f560e70a5d0467c58f29b9664d75;hp=5c9c953050a6464f280c8ee5ab013ddae2a326bf;hpb=b8ac498face4c8b16c06d30fbc86666b7dc28173;p=haskell-directory.git diff --git a/Data/Ratio.hs b/Data/Ratio.hs index 5c9c953..22f3abe 100644 --- a/Data/Ratio.hs +++ b/Data/Ratio.hs @@ -50,11 +50,18 @@ import Ratio (Ratio(..), (%), numerator, denominator, approxRational) -- ----------------------------------------------------------------------------- -- approxRational --- @approxRational@, applied to two real fractional numbers x and epsilon, --- returns the simplest rational number within epsilon of x. A rational --- number n%d in reduced form is said to be simpler than another n'%d' if --- abs n <= abs n' && d <= d'. Any real interval contains a unique --- simplest rational; here, for simplicity, we assume a closed rational +-- | 'approxRational', applied to two real fractional numbers @x@ and @epsilon@, +-- returns the simplest rational number within @epsilon@ of @x@. +-- A rational number @y@ is said to be /simpler/ than another @y'@ if +-- +-- * @'abs' ('numerator' y) <= 'abs' ('numerator' y')@, and +-- +-- * @'denominator' y <= 'denominator' y'@. +-- +-- Any real interval contains a unique simplest rational; +-- in particular, note that @0\/1@ is the simplest rational of all. + +-- Implementation details: Here, for simplicity, we assume a closed rational -- interval. If such an interval includes at least one whole number, then -- the simplest rational is the absolutely least whole number. Otherwise, -- the bounds are of the form q%1 + r%d and q%1 + r'%d', where abs r < d