|
GHC.Real | Portability | non-portable (GHC Extensions) | Stability | internal | Maintainer | cvs-ghc@haskell.org |
|
|
|
Description |
The types Ratio and Rational, and the classes Real, Fractional,
Integral, and RealFrac.
|
|
Synopsis |
|
data Integral a => Ratio a = !a :% !a | | type Rational = Ratio Integer | | ratioPrec1 :: Int | | notANumber :: Rational | | (%) :: Integral a => a -> a -> Ratio a | | numerator :: Integral a => Ratio a -> a | | denominator :: Integral a => Ratio a -> a | | reduce :: Integral a => a -> a -> Ratio a | | class (Num a, Ord a) => Real a where | | | class (Real a, Enum a) => Integral a where | | | class Num a => Fractional a where | | | class (Real a, Fractional a) => RealFrac a where | | | numericEnumFrom :: Fractional a => a -> [a] | | numericEnumFromThen :: Fractional a => a -> a -> [a] | | numericEnumFromTo :: (Ord a, Fractional a) => a -> a -> [a] | | numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a] | | fromIntegral :: (Integral a, Num b) => a -> b | | realToFrac :: (Real a, Fractional b) => a -> b | | showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS | | odd :: Integral a => a -> Bool | | (^) :: (Num a, Integral b) => a -> b -> a | | (^^) :: (Fractional a, Integral b) => a -> b -> a | | gcd :: Integral a => a -> a -> a | | lcm :: Integral a => a -> a -> a | | integralEnumFrom :: (Integral a, Bounded a) => a -> [a] | | integralEnumFromThen :: (Integral a, Bounded a) => a -> a -> [a] | | integralEnumFromTo :: Integral a => a -> a -> [a] | | integralEnumFromThenTo :: Integral a => a -> a -> a -> [a] |
|
|
Documentation |
|
data Integral a => Ratio a |
Rational numbers, with numerator and denominator of some Integral type.
| Constructors | | Instances | |
|
|
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.
|
|
ratioPrec1 :: Int |
|
notANumber :: Rational |
|
(%) :: Integral a => a -> a -> Ratio a |
|
numerator :: Integral a => Ratio a -> a |
Extract the numerator of the ratio in reduced form:
the numerator and denominator have no common factor and the denominator
is positive.
|
|
denominator :: Integral a => Ratio a -> a |
Extract the denominator of the ratio in reduced form:
the numerator and denominator have no common factor and the denominator
is positive.
|
|
reduce :: Integral a => a -> a -> Ratio a |
|
class (Num a, Ord a) => Real a where |
| Methods | toRational :: a -> Rational | the rational equivalent of its real argument with full precision
|
| | Instances | |
|
|
class (Real a, Enum a) => Integral a where |
Integral numbers, supporting integer division.
Minimal complete definition: quotRem and toInteger
| | Methods | quot :: a -> a -> a | integer division truncated toward zero
| | rem :: a -> a -> a | integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
| | div :: a -> a -> a | integer division truncated toward negative infinity
| | mod :: a -> a -> a | integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
| | quotRem :: a -> a -> (a, a) | simultaneous quot and rem
| | divMod :: a -> a -> (a, a) | simultaneous div and mod
| | toInteger :: a -> Integer | conversion to Integer
|
| | Instances | |
|
|
class Num a => Fractional a where |
Fractional numbers, supporting real division.
Minimal complete definition: fromRational and (recip or (/))
| | Methods | (/) :: a -> a -> a | fractional division
| | recip :: a -> a | reciprocal fraction
| | fromRational :: Rational -> a | Conversion from a Rational (that is Ratio Integer).
A floating literal stands for an application of fromRational
to a value of type Rational, so such literals have type
(Fractional a) => a.
|
| | Instances | |
|
|
class (Real a, Fractional a) => RealFrac a where |
Extracting components of fractions.
Minimal complete definition: properFraction
| | 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:
- n is an integral number with the same sign as x; and
- f is a fraction with the same type and sign as x,
and with absolute value less than 1.
The default definitions of the ceiling, floor, truncate
and round functions are in terms of properFraction.
| | truncate :: Integral b => a -> b | truncate x returns the integer nearest x between zero and x
| | round :: Integral b => a -> b | round x returns the nearest integer to x
| | ceiling :: Integral b => a -> b | ceiling x returns the least integer not less than x
| | floor :: Integral b => a -> b | floor x returns the greatest integer not greater than x
|
| | Instances | |
|
|
numericEnumFrom :: Fractional a => a -> [a] |
|
numericEnumFromThen :: Fractional a => a -> a -> [a] |
|
numericEnumFromTo :: (Ord a, Fractional a) => a -> a -> [a] |
|
numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a] |
|
fromIntegral :: (Integral a, Num b) => a -> b |
general coercion from integral types
|
|
realToFrac :: (Real a, Fractional b) => a -> b |
general coercion to fractional types
|
|
showSigned |
:: Real a | | => a -> ShowS | a function that can show unsigned values
| -> Int | the precedence of the enclosing context
| -> a | the value to show
| -> ShowS | | Converts a possibly-negative Real value to a string.
|
|
|
odd :: Integral a => a -> Bool |
|
(^) :: (Num a, Integral b) => a -> b -> a |
|
(^^) :: (Fractional a, Integral b) => a -> b -> a |
|
gcd :: Integral a => a -> a -> a |
gcd x y is the greatest (positive) integer that divides both x
and y; for example gcd (-3) 6 = 3, gcd (-3) (-6) = 3,
gcd 0 4 = 4. gcd 0 0 raises a runtime error.
|
|
lcm :: Integral a => a -> a -> a |
lcm x y is the smallest positive integer that both x and y divide.
|
|
integralEnumFrom :: (Integral a, Bounded a) => a -> [a] |
|
integralEnumFromThen :: (Integral a, Bounded a) => a -> a -> [a] |
|
integralEnumFromTo :: Integral a => a -> a -> [a] |
|
integralEnumFromThenTo :: Integral a => a -> a -> a -> [a] |
|
Produced by Haddock version 2.2.2 |