X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=Data%2FRatio.hs;h=22f3abeeeff8661ee1dc5a620db4d98e9abc1fff;hb=7acdd16c9b9058c39ab2aea39e0f2ef879f8f89c;hp=d71551e196209d27d4e67ea675ce03be4a027b28;hpb=9fa9bc17072a58c0bae2cce4764d38677e96ac29;p=haskell-directory.git diff --git a/Data/Ratio.hs b/Data/Ratio.hs index d71551e..22f3abe 100644 --- a/Data/Ratio.hs +++ b/Data/Ratio.hs @@ -2,14 +2,12 @@ -- | -- Module : Data.Ratio -- Copyright : (c) The University of Glasgow 2001 --- License : BSD-style (see the file libraries/core/LICENSE) +-- License : BSD-style (see the file libraries/base/LICENSE) -- -- Maintainer : libraries@haskell.org --- Stability : provisional +-- Stability : stable -- Portability : portable -- --- $Id: Ratio.hs,v 1.2 2002/04/24 16:31:40 simonmar Exp $ --- -- Standard functions on rational numbers -- ----------------------------------------------------------------------------- @@ -41,14 +39,29 @@ import Prelude import GHC.Real -- The basic defns for Ratio #endif +#ifdef __HUGS__ +import Hugs.Prelude(Ratio(..), (%), numerator, denominator) +#endif + +#ifdef __NHC__ +import Ratio (Ratio(..), (%), numerator, denominator, approxRational) +#else + -- ----------------------------------------------------------------------------- -- 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 @@ -78,4 +91,4 @@ approxRational rat eps = simplest (rat-eps) (rat+eps) nd'' = simplest' d' r' d r n'' = numerator nd'' d'' = denominator nd'' - +#endif