| Safe Haskell | None |
|---|---|
| Language | Haskell2010 |
NumHask.Data.Rational
Description
Rational classes
Documentation
A rational number
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 Integer
13176795 :% 4194304
Minimal complete definition
Nothing
Methods
Instances
class FromRatio a b where Source #
Fractional in base splits into fromRatio and Field
>>>fromRatio (5 :% 2 :: Ratio Integer) :: Double2.5
Minimal complete definition
Nothing
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 (Ratio Integer) Source # | |
Defined in NumHask.Data.Rational | |
reduce :: (Eq a, Subtractive a, Signed a, Integral a) => a -> a -> Ratio a Source #
reduce normalises a ratio by dividing both numerator and denominator by
their greatest common divisor.
gcd :: (Eq a, Signed 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