base-3.0.1.0: Basic librariesSource codeContentsIndex
GHC.Real
Portabilitynon-portable (GHC Extensions)
Stabilityinternal
Maintainercvs-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
ratioPrec :: Int
notANumber :: Rational
infinity :: 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
toRational :: a -> Rational
class (Real a, Enum a) => Integral a where
quot :: a -> a -> a
rem :: a -> a -> a
div :: a -> a -> a
mod :: a -> a -> a
quotRem :: a -> a -> (a, a)
divMod :: a -> a -> (a, a)
toInteger :: a -> Integer
class Num a => Fractional a where
(/) :: a -> a -> a
recip :: a -> a
fromRational :: Rational -> a
class (Real a, Fractional a) => RealFrac a where
properFraction :: Integral b => a -> (b, a)
truncate :: Integral b => a -> b
round :: Integral b => a -> b
ceiling :: Integral b => a -> b
floor :: Integral b => a -> b
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
even :: 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 Source
Rational numbers, with numerator and denominator of some Integral type.
Constructors
!a :% !a
show/hide Instances
type Rational = Ratio IntegerSource
Arbitrary-precision rational numbers, represented as a ratio of two Integer values. A rational number may be constructed using the % operator.
ratioPrec1 :: IntSource
ratioPrec :: IntSource
notANumber :: RationalSource
infinity :: RationalSource
(%) :: Integral a => a -> a -> Ratio aSource
Forms the ratio of two integral numbers.
numerator :: Integral a => Ratio a -> aSource
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 -> aSource
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 aSource
class (Num a, Ord a) => Real a whereSource
Methods
toRational :: a -> RationalSource
the rational equivalent of its real argument with full precision
show/hide Instances
class (Real a, Enum a) => Integral a whereSource

Integral numbers, supporting integer division.

Minimal complete definition: quotRem and toInteger

Methods
quot :: a -> a -> aSource
integer division truncated toward zero
rem :: a -> a -> aSource

integer remainder, satisfying

 (x `quot` y)*y + (x `rem` y) == x
div :: a -> a -> aSource
integer division truncated toward negative infinity
mod :: a -> a -> aSource

integer modulus, satisfying

 (x `div` y)*y + (x `mod` y) == x
quotRem :: a -> a -> (a, a)Source
simultaneous quot and rem
divMod :: a -> a -> (a, a)Source
simultaneous div and mod
toInteger :: a -> IntegerSource
conversion to Integer
show/hide Instances
class Num a => Fractional a whereSource

Fractional numbers, supporting real division.

Minimal complete definition: fromRational and (recip or (/))

Methods
(/) :: a -> a -> aSource
fractional division
recip :: a -> aSource
reciprocal fraction
fromRational :: Rational -> aSource
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.
show/hide Instances
class (Real a, Fractional a) => RealFrac a whereSource

Extracting components of fractions.

Minimal complete definition: properFraction

Methods
properFraction :: Integral b => a -> (b, a)Source

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 -> bSource
truncate x returns the integer nearest x between zero and x
round :: Integral b => a -> bSource
round x returns the nearest integer to x
ceiling :: Integral b => a -> bSource
ceiling x returns the least integer not less than x
floor :: Integral b => a -> bSource
floor x returns the greatest integer not greater than x
show/hide Instances
numericEnumFrom :: Fractional a => a -> [a]Source
numericEnumFromThen :: Fractional a => a -> a -> [a]Source
numericEnumFromTo :: (Ord a, Fractional a) => a -> a -> [a]Source
numericEnumFromThenTo :: (Ord a, Fractional a) => a -> a -> a -> [a]Source
fromIntegral :: (Integral a, Num b) => a -> bSource
general coercion from integral types
realToFrac :: (Real a, Fractional b) => a -> bSource
general coercion to fractional types
showSignedSource
:: Real a
=> a -> ShowSa function that can show unsigned values
-> Intthe precedence of the enclosing context
-> athe value to show
-> ShowS
Converts a possibly-negative Real value to a string.
odd :: Integral a => a -> BoolSource
even :: Integral a => a -> BoolSource
(^) :: (Num a, Integral b) => a -> b -> aSource
raise a number to a non-negative integral power
(^^) :: (Fractional a, Integral b) => a -> b -> aSource
raise a number to an integral power
gcd :: Integral a => a -> a -> aSource
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 -> aSource
lcm x y is the smallest positive integer that both x and y divide.
integralEnumFrom :: (Integral a, Bounded a) => a -> [a]Source
integralEnumFromThen :: (Integral a, Bounded a) => a -> a -> [a]Source
integralEnumFromTo :: Integral a => a -> a -> [a]Source
integralEnumFromThenTo :: Integral a => a -> a -> a -> [a]Source
Produced by Haddock version 2.0.0.0