| Safe Haskell | Safe-Inferred |
|---|---|
| Language | Haskell2010 |
Prelude.Source.GHC.Real
- type Rational = Ratio Integer
- class (Num a, Ord a) => Real a where
- toRational :: a -> Rational
- class (Real a, Enum a) => Integral a where
- class Num a => Fractional a where
- (/) :: a -> a -> a
- recip :: a -> a
- fromRational :: Rational -> a
- class (Real a, Fractional a) => RealFrac a where
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- (^) :: (Num a, Integral b) => a -> b -> a
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- fromIntegral :: (Integral a, Num b) => a -> b
- realToFrac :: (Real a, Fractional b) => a -> b
Documentation
class (Real a, Enum a) => Integral a where
Methods
quot :: a -> a -> a infixl 7
integer division truncated toward zero
rem :: a -> a -> a infixl 7
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
div :: a -> a -> a infixl 7
integer division truncated toward negative infinity
mod :: a -> a -> a infixl 7
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
quotRem :: a -> a -> (a, a)
divMod :: a -> a -> (a, a)
conversion to Integer
class Num a => Fractional a where
Fractional numbers, supporting real division.
Minimal complete definition: fromRational and (recip or ()/)
Minimal complete definition
fromRational, (recip | (/))
Methods
(/) :: a -> a -> a infixl 7
fractional division
recip :: a -> a
reciprocal fraction
fromRational :: Rational -> a
Conversion from a Rational (that is ).
A floating literal stands for an application of Ratio IntegerfromRational
to a value of type Rational, so such literals have type
(.Fractional a) => a
Instances
| Fractional Double | |
| Fractional Float | |
| Integral a => Fractional (Ratio a) |
class (Real a, Fractional a) => RealFrac a where
Extracting components of fractions.
Minimal complete definition: properFraction
Minimal complete definition
Methods
properFraction :: Integral b => a -> (b, a)
The function properFraction takes a real fractional number x
and returns a pair (n,f) such that x = n+f, and:
nis an integral number with the same sign asx; andfis a fraction with the same type and sign asx, and with absolute value less than1.
The default definitions of the ceiling, floor, truncate
and round functions are in terms of properFraction.
truncate :: Integral b => a -> b
returns the integer nearest truncate xx between zero and x
returns the nearest integer to round xx;
the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b
returns the least integer not less than ceiling xx
returns the greatest integer not greater than floor xx
gcd :: Integral a => a -> a -> a
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
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8
raise a number to an integral power
fromIntegral :: (Integral a, Num b) => a -> b
general coercion from integral types
realToFrac :: (Real a, Fractional b) => a -> b
general coercion to fractional types