| 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
| ToRatio Double Integer Source # | |
| ToRatio Float Integer Source # | |
| ToRatio Int Integer Source # | |
| ToRatio Int8 Integer Source # | |
| ToRatio Int16 Integer Source # | |
| ToRatio Int32 Integer Source # | |
| ToRatio Int64 Integer Source # | |
| ToRatio Integer Integer Source # | |
| ToRatio Natural Integer Source # | |
| ToRatio Rational Integer Source # | |
| ToRatio Word Integer Source # | |
| ToRatio Word8 Integer Source # | |
| ToRatio Word16 Integer Source # | |
| ToRatio Word32 Integer Source # | |
| ToRatio Word64 Integer Source # | |
| ToRatio (Ratio Integer) Integer Source # | |
| (ToRatio a b, ExpField a) => ToRatio (LogField a) b Source # | |
| ToRatio a b => ToRatio (Wrapped a) b Source # | |
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 #
gcd x yx and y of which
 every common factor of x and y is also a factor; for example
 gcd 4 2 = 2gcd (-4) 6 = 2gcd 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, abs minBound < 0minBound0 or minBound