base-3.0.2.0: Basic librariesContentsIndex
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
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
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
(^) :: (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
!a :% !a
show/hide 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
show/hide 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
show/hide 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.
show/hide 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
show/hide 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 -> 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 -> 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