| Safe Haskell | Safe-Inferred | 
|---|---|
| Language | GHC2021 | 
NumHask.Data.Rational
Description
Rational classes
Documentation
A rational number, represented as the ratio of two Integral numbers.
Constructors
| !a :% !a | 
Instances
class ToRatio a b where Source #
toRatio is equivalent to Real in base, but is polymorphic in the Integral type.
>>>toRatio (3.1415927 :: Float) :: Ratio Integer13176795 :% 4194304
Instances
class FromRatio a b where Source #
Fractional in base splits into fromRatio and Field
>>>fromRatio (5 :% 2 :: Ratio Integer) :: Double2.5
class FromRational a where Source #
fromRational is special in two ways:
- numeric decimal literals (like "53.66") are interpreted as exactly "fromRational (53.66 :: GHC.Real.Ratio Integer)". The prelude version, GHC.Real.fromRational is used as default (or whatever is in scope if RebindableSyntax is set).
 - The default rules in haskell2010 specify that contraints on 
fromRationalneed to be in a formC v, where v is a Num or a subclass of Num. 
So a type synonym of `type FromRational a = FromRatio a Integer` doesn't work well with type defaulting; hence the need for a separate class.
Methods
fromRational :: Rational -> a Source #
Instances
| FromRational Double Source # | |
Defined in NumHask.Data.Rational Methods fromRational :: Rational -> Double Source #  | |
| FromRational Float Source # | |
Defined in NumHask.Data.Rational Methods fromRational :: Rational -> Float Source #  | |
| FromRational a => FromRational (Positive a) Source # | |
Defined in NumHask.Data.Positive Methods fromRational :: Rational -> Positive a Source #  | |
| FromRational (Ratio Integer) Source # | |
Defined in NumHask.Data.Rational  | |
| FromRational a => FromRational (Wrapped a) Source # | |
Defined in NumHask.Data.Wrapped Methods fromRational :: Rational -> Wrapped a Source #  | |
reduce :: (Eq a, Subtractive a, EndoBased a, Integral a) => a -> a -> Ratio a Source #
reduce normalises a ratio by dividing both numerator and denominator by
 their greatest common divisor.
>>>reduce 72 606 :% 5
\a b -> reduce a b == a :% b || b == zero
gcd :: (Eq a, EndoBased a, Integral a) => a -> a -> a Source #
 is the non-negative factor of both gcd x yx and y of which
 every common factor of x and y is also a factor; for example
 , gcd 4 2 = 2, gcd (-4) 6 = 2 = gcd 0 44.  = gcd 0 00.
 (That is, the common divisor that is "greatest" in the divisibility
 preordering.)
Note: Since for signed fixed-width integer types, ,
 the result may be negative if one of the arguments is abs minBound < 0 (and
 necessarily is if the other is minBound0 or ) for such types.minBound
>>>gcd 72 6012