| Copyright | (c) The University of Glasgow 1994-2002 | 
|---|---|
| License | see libraries/base/LICENSE | 
| Maintainer | cvs-ghc@haskell.org | 
| Stability | internal | 
| Portability | non-portable (GHC Extensions) | 
| Safe Haskell | Trustworthy | 
| Language | Haskell2010 | 
GHC.Real
Synopsis
- divZeroError :: a
- ratioZeroDenominatorError :: a
- overflowError :: a
- underflowError :: a
- data Ratio a = !a :% !a
- type Rational = Ratio Integer
- ratioPrec :: Int
- ratioPrec1 :: Int
- infinity :: Rational
- notANumber :: Rational
- (%) :: Integral a => a -> a -> Ratio a
- numerator :: Ratio a -> a
- denominator :: 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
- class Num a => Fractional a where- (/) :: a -> a -> a
- recip :: a -> a
- fromRational :: Rational -> a
 
- 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
- naturalFromInt :: Int -> Natural
- realToFrac :: (Real a, Fractional b) => a -> b
- showSigned :: Real a => (a -> ShowS) -> Int -> a -> ShowS
- even :: Integral a => a -> Bool
- odd :: Integral a => a -> Bool
- (^) :: (Num a, Integral b) => a -> b -> a
- (^^) :: (Fractional a, Integral b) => a -> b -> a
- (^%^) :: Integral a => Rational -> a -> Rational
- (^^%^^) :: Integral a => Rational -> a -> Rational
- 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
divZeroError :: a #
overflowError :: a #
underflowError :: a #
Rational numbers, with numerator and denominator of some Integral type.
Note that Ratio's instances inherit the deficiencies from the type
 parameter's. For example, Ratio Natural's Num instance has similar
 problems to Natural's.
Constructors
| !a :% !a | 
Instances
| (Data a, Integral a) => Data (Ratio a) # | Since: base-4.0.0.0 | 
| Defined in Data.Data Methods gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Ratio a -> c (Ratio a) # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ratio a) # toConstr :: Ratio a -> Constr # dataTypeOf :: Ratio a -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Ratio a)) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ratio a)) # gmapT :: (forall b. Data b => b -> b) -> Ratio a -> Ratio a # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r # gmapQ :: (forall d. Data d => d -> u) -> Ratio a -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ratio a -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) # | |
| (Storable a, Integral a) => Storable (Ratio a) # | Since: base-4.8.0.0 | 
| Integral a => Enum (Ratio a) # | Since: base-2.0.1 | 
| Integral a => Num (Ratio a) # | Since: base-2.0.1 | 
| (Integral a, Read a) => Read (Ratio a) # | Since: base-2.1 | 
| Integral a => Fractional (Ratio a) # | Since: base-2.0.1 | 
| Integral a => Real (Ratio a) # | Since: base-2.0.1 | 
| Defined in GHC.Real Methods toRational :: Ratio a -> Rational # | |
| Integral a => RealFrac (Ratio a) # | Since: base-2.0.1 | 
| Show a => Show (Ratio a) # | Since: base-2.0.1 | 
| Eq a => Eq (Ratio a) # | Since: base-2.1 | 
| Integral a => Ord (Ratio a) # | Since: base-2.0.1 | 
ratioPrec1 :: Int #
notANumber :: Rational #
Extract the numerator of the ratio in reduced form: the numerator and denominator have no common factor and the denominator is positive.
denominator :: 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 #
reduce is a subsidiary function used only in this module.
 It normalises a ratio by dividing both numerator and denominator by
 their greatest common divisor.
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.
The Haskell Report defines no laws for Integral. However, Integral
 instances are customarily expected to define a Euclidean domain and have the
 following properties for the div/mod and quot/rem pairs, given
 suitable Euclidean functions f and g:
- x=- y * quot x y + rem x ywith- rem x y=- fromInteger 0or- g (rem x y)<- g y
- x=- y * div x y + mod x ywith- mod x y=- fromInteger 0or- f (mod x y)<- f y
An example of a suitable Euclidean function, for Integer's instance, is
 abs.
Methods
quot :: a -> a -> a infixl 7 #
integer division truncated toward zero
integer remainder, satisfying
(x `quot` y)*y + (x `rem` y) == x
integer division truncated toward negative infinity
integer modulus, satisfying
(x `div` y)*y + (x `mod` y) == x
conversion to Integer
Instances
class Num a => Fractional a where #
Fractional numbers, supporting real division.
The Haskell Report defines no laws for Fractional. However, ( and
 +)( are customarily expected to define a division ring and have the
 following properties:*)
- recipgives the multiplicative inverse
- x * recip x=- recip x * x=- fromInteger 1
Note that it isn't customarily expected that a type instance of
 Fractional implement a field. However, all instances in base do.
Minimal complete definition
fromRational, (recip | (/))
Methods
Fractional division.
Reciprocal fraction.
fromRational :: Rational -> a #
Conversion from a Rational (that is Ratio IntegerfromRational
 to a value of type Rational, so such literals have type
 (.Fractional a) => a
Instances
| Fractional CDouble # | |
| Fractional CFloat # | |
| Fractional Double # | Note that due to the presence of  
 Since: base-2.1 | 
| Fractional Float # | Note that due to the presence of  
 Since: base-2.1 | 
| RealFloat a => Fractional (Complex a) # | Since: base-2.1 | 
| Fractional a => Fractional (Identity a) # | Since: base-4.9.0.0 | 
| Fractional a => Fractional (Down a) # | Since: base-4.14.0.0 | 
| Integral a => Fractional (Ratio a) # | Since: base-2.0.1 | 
| HasResolution a => Fractional (Fixed a) # | Since: base-2.1 | 
| Fractional a => Fractional (Op a b) # | |
| Fractional a => Fractional (Const a b) # | Since: base-4.9.0.0 | 
class (Real a, Fractional a) => RealFrac a where #
Extracting components of fractions.
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 as- x; and
- fis 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 xx between zero and x
round :: Integral b => a -> b #
round xx;
   the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b #
ceiling xx
floor :: Integral b => a -> b #
floor xx
Instances
| RealFrac CDouble # | |
| RealFrac CFloat # | |
| RealFrac Double # | Since: base-2.1 | 
| RealFrac Float # | Since: base-2.1 | 
| RealFrac a => RealFrac (Identity a) # | Since: base-4.9.0.0 | 
| RealFrac a => RealFrac (Down a) # | Since: base-4.14.0.0 | 
| Integral a => RealFrac (Ratio a) # | Since: base-2.0.1 | 
| HasResolution a => RealFrac (Fixed a) # | Since: base-2.1 | 
| RealFrac a => RealFrac (Const a b) # | Since: base-4.9.0.0 | 
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
naturalFromInt :: Int -> Natural #
Convert an Int into a Natural, throwing an underflow exception for negative values.
realToFrac :: (Real a, Fractional b) => a -> b #
general coercion to fractional types
Arguments
| :: 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.
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 #
raise a number to an integral power
gcd :: Integral a => a -> a -> a #
gcd x yx and y of which
 every common factor of x and y is also a factor; for example
 gcd 4 2 = 2gcd (-4) 6 = 2gcd 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, abs minBound < 0minBound0 or minBound
lcm :: Integral a => a -> a -> a #
lcm x yx 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] #