base-4.8.2.0: Basic libraries

Data.Ratio

Description

Standard functions on rational numbers

Synopsis

# Documentation

data Ratio a Source

Rational numbers, with numerator and denominator of some `Integral` type.

Instances

 Integral a => Enum (Ratio a) Source Methodssucc :: Ratio a -> Ratio a Sourcepred :: Ratio a -> Ratio a SourcetoEnum :: Int -> Ratio a SourcefromEnum :: Ratio a -> Int SourceenumFrom :: Ratio a -> [Ratio a] SourceenumFromThen :: Ratio a -> Ratio a -> [Ratio a] SourceenumFromTo :: Ratio a -> Ratio a -> [Ratio a] SourceenumFromThenTo :: Ratio a -> Ratio a -> Ratio a -> [Ratio a] Source Eq a => Eq (Ratio a) Source Methods(==) :: Ratio a -> Ratio a -> Bool(/=) :: Ratio a -> Ratio a -> Bool Integral a => Fractional (Ratio a) Source Methods(/) :: Ratio a -> Ratio a -> Ratio a Sourcerecip :: Ratio a -> Ratio a Source (Data a, Integral a) => Data (Ratio a) Source Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ratio a -> c (Ratio a) Sourcegunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ratio a) SourcedataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c (Ratio a)) SourcedataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ratio a)) SourcegmapT :: (forall b. Data b => b -> b) -> Ratio a -> Ratio a SourcegmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r SourcegmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r SourcegmapQ :: (forall d. Data d => d -> u) -> Ratio a -> [u] SourcegmapQi :: Int -> (forall d. Data d => d -> u) -> Ratio a -> u SourcegmapM :: Monad m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) SourcegmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) SourcegmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source Integral a => Num (Ratio a) Source Methods(+) :: Ratio a -> Ratio a -> Ratio a Source(-) :: Ratio a -> Ratio a -> Ratio a Source(*) :: Ratio a -> Ratio a -> Ratio a Sourcenegate :: Ratio a -> Ratio a Sourceabs :: Ratio a -> Ratio a Sourcesignum :: Ratio a -> Ratio a Source Integral a => Ord (Ratio a) Source Methodscompare :: Ratio a -> Ratio a -> Ordering(<) :: Ratio a -> Ratio a -> Bool(<=) :: Ratio a -> Ratio a -> Bool(>) :: Ratio a -> Ratio a -> Bool(>=) :: Ratio a -> Ratio a -> Boolmax :: Ratio a -> Ratio a -> Ratio amin :: Ratio a -> Ratio a -> Ratio a (Integral a, Read a) => Read (Ratio a) Source MethodsreadsPrec :: Int -> ReadS (Ratio a) Source Integral a => Real (Ratio a) Source Methods Integral a => RealFrac (Ratio a) Source MethodsproperFraction :: Integral b => Ratio a -> (b, Ratio a) Sourcetruncate :: Integral b => Ratio a -> b Sourceround :: Integral b => Ratio a -> b Sourceceiling :: Integral b => Ratio a -> b Sourcefloor :: Integral b => Ratio a -> b Source (Integral a, Show a) => Show (Ratio a) Source MethodsshowsPrec :: Int -> Ratio a -> ShowS Sourceshow :: Ratio a -> String SourceshowList :: [Ratio a] -> ShowS Source (Storable a, Integral a) => Storable (Ratio a) Source MethodssizeOf :: Ratio a -> Int Sourcealignment :: Ratio a -> Int SourcepeekElemOff :: Ptr (Ratio a) -> Int -> IO (Ratio a) SourcepokeElemOff :: Ptr (Ratio a) -> Int -> Ratio a -> IO () SourcepeekByteOff :: Ptr b -> Int -> IO (Ratio a) SourcepokeByteOff :: Ptr b -> Int -> Ratio a -> IO () Sourcepeek :: Ptr (Ratio a) -> IO (Ratio a) Sourcepoke :: Ptr (Ratio a) -> Ratio a -> IO () Source

Arbitrary-precision rational numbers, represented as a ratio of two `Integer` values. A rational number may be constructed using the `%` operator.

(%) :: Integral a => a -> a -> Ratio a infixl 7 Source

Forms the ratio of two integral numbers.

numerator :: Integral a => Ratio a -> a Source

Extract the numerator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.

denominator :: Integral a => Ratio a -> a Source

Extract the denominator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.

approxRational :: RealFrac a => a -> a -> Rational Source

`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.