numhask-0.8.1.0: A numeric class hierarchy.
Safe HaskellNone
LanguageHaskell2010

NumHask.Data.Rational

Description

Rational classes

Synopsis

Documentation

data Ratio a Source #

A rational number

Constructors

!a :% !a 

Instances

Instances details
(Eq a, Additive a) => Eq (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

(==) :: Ratio a -> Ratio a -> Bool #

(/=) :: Ratio a -> Ratio a -> Bool #

(Ord a, Multiplicative a, Additive a) => Ord (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

compare :: Ratio a -> Ratio a -> Ordering #

(<) :: Ratio a -> Ratio a -> Bool #

(<=) :: Ratio a -> Ratio a -> Bool #

(>) :: Ratio a -> Ratio a -> Bool #

(>=) :: Ratio a -> Ratio a -> Bool #

max :: Ratio a -> Ratio a -> Ratio a #

min :: Ratio a -> Ratio a -> Ratio a #

Show a => Show (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

showsPrec :: Int -> Ratio a -> ShowS #

show :: Ratio a -> String #

showList :: [Ratio a] -> ShowS #

(Ord a, Signed a, Integral a, Ring a) => Subtractive (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

negate :: Ratio a -> Ratio a Source #

(-) :: Ratio a -> Ratio a -> Ratio a Source #

(Ord a, Signed a, Integral a, Ring a) => Additive (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

(+) :: Ratio a -> Ratio a -> Ratio a Source #

zero :: Ratio a Source #

(Ord a, Signed a, Integral a, Ring a) => Divisive (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

recip :: Ratio a -> Ratio a Source #

(/) :: Ratio a -> Ratio a -> Ratio a Source #

(Ord a, Signed a, Integral a, Ring a, Multiplicative a) => Multiplicative (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

(*) :: Ratio a -> Ratio a -> Ratio a Source #

one :: Ratio a Source #

(Ord a, Signed a, Integral a, Ring a) => Distributive (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

(Ord a, Signed a, Integral a, Field a) => LowerBoundedField (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

(Ord a, Signed a, Integral a, Ring a, Distributive a) => UpperBoundedField (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

(Ord a, Signed a, Integral a, Ring a) => Field (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

(Ord a, Signed a) => MeetSemiLattice (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

(/\) :: Ratio a -> Ratio a -> Ratio a Source #

(Ord a, Signed a) => JoinSemiLattice (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

(\/) :: Ratio a -> Ratio a -> Ratio a Source #

(Ord a, Signed a, Integral a, Ring a, MeetSemiLattice a) => Epsilon (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

(Ord a, Signed a, Integral a, Ring a) => Signed (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

sign :: Ratio a -> Ratio a Source #

abs :: Ratio a -> Ratio a Source #

FromRational (Ratio Integer) Source # 
Instance details

Defined in NumHask.Data.Rational

(FromIntegral a b, Multiplicative a) => FromIntegral (Ratio a) b Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

fromIntegral :: b -> Ratio a Source #

(Ord a, Signed a, Integral a, Ring a, Ord b, Signed b, Integral b, Ring b, Field a, FromIntegral b a) => QuotientField (Ratio a) b Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

properFraction :: Ratio a -> (b, Ratio a) Source #

round :: Ratio a -> b Source #

ceiling :: Ratio a -> b Source #

floor :: Ratio a -> b Source #

truncate :: Ratio a -> b Source #

ToRatio (Ratio Integer) Integer Source # 
Instance details

Defined in NumHask.Data.Rational

(Ord a, Signed a, Integral a, Ring a) => Norm (Ratio a) (Ratio a) Source # 
Instance details

Defined in NumHask.Data.Rational

Methods

norm :: Ratio a -> Ratio a Source #

basis :: Ratio a -> Ratio a Source #

type Rational = Ratio Integer #

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

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

toRatio :: a -> Ratio b Source #

default toRatio :: (Ratio c ~ a, FromIntegral b c, ToRatio (Ratio b) b) => a -> Ratio b Source #

Instances

Instances details
ToRatio Double Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Float Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Int Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Int8 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Int16 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Int32 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Int64 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Integer Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Natural Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Rational Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Word Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Word8 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Word16 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Word32 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio Word64 Integer Source # 
Instance details

Defined in NumHask.Data.Rational

ToRatio (Ratio Integer) Integer Source # 
Instance details

Defined in NumHask.Data.Rational

class FromRatio a b where Source #

Fractional in base splits into fromRatio and Field

>>> fromRatio (5 :% 2 :: Ratio Integer) :: Double
2.5

Minimal complete definition

Nothing

Methods

fromRatio :: Ratio b -> a Source #

default fromRatio :: Ratio b ~ a => Ratio b -> a Source #

Instances

Instances details
FromRatio Double Integer Source # 
Instance details

Defined in NumHask.Data.Rational

FromRatio Float Integer Source # 
Instance details

Defined in NumHask.Data.Rational

FromRatio Rational Integer Source # 
Instance details

Defined in NumHask.Data.Rational

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 fromRational need to be in a form C 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

Instances details
FromRational Double Source # 
Instance details

Defined in NumHask.Data.Rational

FromRational Float Source # 
Instance details

Defined in NumHask.Data.Rational

FromRational (Ratio Integer) Source # 
Instance details

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 y is the non-negative factor of both x 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 4 = 4. gcd 0 0 = 0. (That is, the common divisor that is "greatest" in the divisibility preordering.)

Note: Since for signed fixed-width integer types, abs minBound < 0, the result may be negative if one of the arguments is minBound (and necessarily is if the other is 0 or minBound) for such types.