ghc-internal-9.1400.0: Basic libraries
Copyright(c) The University of Glasgow 1994-2002
Licensesee libraries/base/LICENSE
Maintainerghc-devs@haskell.org
Stabilityinternal
Portabilitynon-portable (GHC Extensions)
Safe HaskellTrustworthy
LanguageHaskell2010

GHC.Internal.Real

Description

The types Ratio and Rational, and the classes Real, Fractional, Integral, and RealFrac.

Synopsis

Classes

class (Num a, Ord a) => Real a where #

Real numbers.

The Haskell report defines no laws for Real, however Real instances are customarily expected to adhere to the following law:

Coherence with fromRational
if the type also implements Fractional, then fromRational is a left inverse for toRational, i.e. fromRational (toRational i) = i

The law does not hold for Float, Double, CFloat, CDouble, etc., because these types contain non-finite values, which cannot be roundtripped through Rational.

Methods

toRational :: a -> Rational #

Rational equivalent of its real argument with full precision.

Instances

Instances details
Real CBool # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CBool -> Rational #

Real CChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CChar -> Rational #

Real CClock # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CDouble # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CFloat # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CInt # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CInt -> Rational #

Real CIntMax # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CIntPtr # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CLLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CLong -> Rational #

Real CPtrdiff # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CSChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CSUSeconds # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CShort # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CSigAtomic # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CSize # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CSize -> Rational #

Real CTime # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CTime -> Rational #

Real CUChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CUInt # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

toRational :: CUInt -> Rational #

Real CUIntMax # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CUIntPtr # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CULLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CULong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CUSeconds # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CUShort # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real CWchar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Real IntPtr # 
Instance details

Defined in GHC.Internal.Foreign.Ptr

Real WordPtr # 
Instance details

Defined in GHC.Internal.Foreign.Ptr

Real HalfWord # 
Instance details

Defined in GHC.Internal.Heap.InfoTable.Types

Real Int16 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Methods

toRational :: Int16 -> Rational #

Real Int32 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Methods

toRational :: Int32 -> Rational #

Real Int64 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Methods

toRational :: Int64 -> Rational #

Real Int8 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Methods

toRational :: Int8 -> Rational #

Real ByteOffset # 
Instance details

Defined in GHC.Internal.Stack.Constants

Real WordOffset # 
Instance details

Defined in GHC.Internal.Stack.Constants

Real ByteOffset # 
Instance details

Defined in GHC.Internal.Stack.ConstantsProf

Real WordOffset # 
Instance details

Defined in GHC.Internal.Stack.ConstantsProf

Real CBlkCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CBlkSize # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CCc # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CCc -> Rational #

Real CClockId # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CDev # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CDev -> Rational #

Real CFsBlkCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CFsFilCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CGid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CGid -> Rational #

Real CId # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CId -> Rational #

Real CIno # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CIno -> Rational #

Real CKey # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CKey -> Rational #

Real CMode # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CMode -> Rational #

Real CNfds # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CNfds -> Rational #

Real CNlink # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real COff # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: COff -> Rational #

Real CPid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CPid -> Rational #

Real CRLim # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CRLim -> Rational #

Real CSocklen # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CSpeed # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CSsize # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CTcflag # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Real CUid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: CUid -> Rational #

Real Fd # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

toRational :: Fd -> Rational #

Real Word16 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Real Word32 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Real Word64 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Real Word8 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Methods

toRational :: Word8 -> Rational #

Real Integer #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Real Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Real

Real Double #

Beware that toRational generates garbage for non-finite arguments:

>>> toRational (1/0)
179769313 (and 300 more digits...) % 1
>>> toRational (0/0)
269653970 (and 300 more digits...) % 1

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Real Float #

Beware that toRational generates garbage for non-finite arguments:

>>> toRational (1/0 :: Float)
340282366920938463463374607431768211456 % 1
>>> toRational (0/0 :: Float)
510423550381407695195061911147652317184 % 1

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Methods

toRational :: Float -> Rational #

Real Int #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

toRational :: Int -> Rational #

Real Word #

Since: base-2.1

Instance details

Defined in GHC.Internal.Real

Methods

toRational :: Word -> Rational #

Real a => Real (Identity a) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Identity

Methods

toRational :: Identity a -> Rational #

Real a => Real (Down a) #

Since: base-4.14.0.0

Instance details

Defined in GHC.Internal.Data.Ord

Methods

toRational :: Down a -> Rational #

Integral a => Real (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

toRational :: Ratio a -> Rational #

Real a => Real (Const a b) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Const

Methods

toRational :: Const a b -> Rational #

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 y with rem x y = fromInteger 0 or g (rem x y) < g y
  • x = y * div x y + mod x y with mod x y = fromInteger 0 or f (mod x y) < f y

An example of a suitable Euclidean function, for Integer's instance, is abs.

In addition, toInteger should be total, and fromInteger should be a left inverse for it, i.e. fromInteger (toInteger i) = i.

Minimal complete definition

quotRem, toInteger

Methods

quot :: a -> a -> a infixl 7 #

Integer division truncated toward zero.

WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.

rem :: a -> a -> a infixl 7 #

Integer remainder, satisfying

(x `quot` y)*y + (x `rem` y) == x

WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.

div :: a -> a -> a infixl 7 #

Integer division truncated toward negative infinity.

WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.

mod :: a -> a -> a infixl 7 #

Integer modulus, satisfying

(x `div` y)*y + (x `mod` y) == x

WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.

quotRem :: a -> a -> (a, a) #

Simultaneous quot and rem.

WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.

divMod :: a -> a -> (a, a) #

simultaneous div and mod.

WARNING: This function is partial (because it throws when 0 is passed as the divisor) for all the integer types in base.

toInteger :: a -> Integer #

Conversion to Integer.

Instances

Instances details
Integral CBool # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CInt # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

quot :: CInt -> CInt -> CInt #

rem :: CInt -> CInt -> CInt #

div :: CInt -> CInt -> CInt #

mod :: CInt -> CInt -> CInt #

quotRem :: CInt -> CInt -> (CInt, CInt) #

divMod :: CInt -> CInt -> (CInt, CInt) #

toInteger :: CInt -> Integer #

Integral CIntMax # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CIntPtr # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CLLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CPtrdiff # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CSChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CShort # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CSigAtomic # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CSize # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CUChar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CUInt # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CUIntMax # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CUIntPtr # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CULLong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CULong # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CUShort # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral CWchar # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Integral IntPtr # 
Instance details

Defined in GHC.Internal.Foreign.Ptr

Integral WordPtr # 
Instance details

Defined in GHC.Internal.Foreign.Ptr

Integral HalfWord # 
Instance details

Defined in GHC.Internal.Heap.InfoTable.Types

Integral Int16 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Integral Int32 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Integral Int64 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Integral Int8 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Int

Methods

quot :: Int8 -> Int8 -> Int8 #

rem :: Int8 -> Int8 -> Int8 #

div :: Int8 -> Int8 -> Int8 #

mod :: Int8 -> Int8 -> Int8 #

quotRem :: Int8 -> Int8 -> (Int8, Int8) #

divMod :: Int8 -> Int8 -> (Int8, Int8) #

toInteger :: Int8 -> Integer #

Integral ByteOffset # 
Instance details

Defined in GHC.Internal.Stack.Constants

Integral WordOffset # 
Instance details

Defined in GHC.Internal.Stack.Constants

Integral ByteOffset # 
Instance details

Defined in GHC.Internal.Stack.ConstantsProf

Integral WordOffset # 
Instance details

Defined in GHC.Internal.Stack.ConstantsProf

Integral CBlkCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CBlkSize # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CClockId # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CDev # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CDev -> CDev -> CDev #

rem :: CDev -> CDev -> CDev #

div :: CDev -> CDev -> CDev #

mod :: CDev -> CDev -> CDev #

quotRem :: CDev -> CDev -> (CDev, CDev) #

divMod :: CDev -> CDev -> (CDev, CDev) #

toInteger :: CDev -> Integer #

Integral CFsBlkCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CFsFilCnt # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CGid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CGid -> CGid -> CGid #

rem :: CGid -> CGid -> CGid #

div :: CGid -> CGid -> CGid #

mod :: CGid -> CGid -> CGid #

quotRem :: CGid -> CGid -> (CGid, CGid) #

divMod :: CGid -> CGid -> (CGid, CGid) #

toInteger :: CGid -> Integer #

Integral CId # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CId -> CId -> CId #

rem :: CId -> CId -> CId #

div :: CId -> CId -> CId #

mod :: CId -> CId -> CId #

quotRem :: CId -> CId -> (CId, CId) #

divMod :: CId -> CId -> (CId, CId) #

toInteger :: CId -> Integer #

Integral CIno # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CIno -> CIno -> CIno #

rem :: CIno -> CIno -> CIno #

div :: CIno -> CIno -> CIno #

mod :: CIno -> CIno -> CIno #

quotRem :: CIno -> CIno -> (CIno, CIno) #

divMod :: CIno -> CIno -> (CIno, CIno) #

toInteger :: CIno -> Integer #

Integral CKey # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CKey -> CKey -> CKey #

rem :: CKey -> CKey -> CKey #

div :: CKey -> CKey -> CKey #

mod :: CKey -> CKey -> CKey #

quotRem :: CKey -> CKey -> (CKey, CKey) #

divMod :: CKey -> CKey -> (CKey, CKey) #

toInteger :: CKey -> Integer #

Integral CMode # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CNfds # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CNlink # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral COff # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: COff -> COff -> COff #

rem :: COff -> COff -> COff #

div :: COff -> COff -> COff #

mod :: COff -> COff -> COff #

quotRem :: COff -> COff -> (COff, COff) #

divMod :: COff -> COff -> (COff, COff) #

toInteger :: COff -> Integer #

Integral CPid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CPid -> CPid -> CPid #

rem :: CPid -> CPid -> CPid #

div :: CPid -> CPid -> CPid #

mod :: CPid -> CPid -> CPid #

quotRem :: CPid -> CPid -> (CPid, CPid) #

divMod :: CPid -> CPid -> (CPid, CPid) #

toInteger :: CPid -> Integer #

Integral CRLim # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CSocklen # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CSsize # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CTcflag # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Integral CUid # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: CUid -> CUid -> CUid #

rem :: CUid -> CUid -> CUid #

div :: CUid -> CUid -> CUid #

mod :: CUid -> CUid -> CUid #

quotRem :: CUid -> CUid -> (CUid, CUid) #

divMod :: CUid -> CUid -> (CUid, CUid) #

toInteger :: CUid -> Integer #

Integral Fd # 
Instance details

Defined in GHC.Internal.System.Posix.Types

Methods

quot :: Fd -> Fd -> Fd #

rem :: Fd -> Fd -> Fd #

div :: Fd -> Fd -> Fd #

mod :: Fd -> Fd -> Fd #

quotRem :: Fd -> Fd -> (Fd, Fd) #

divMod :: Fd -> Fd -> (Fd, Fd) #

toInteger :: Fd -> Integer #

Integral Word16 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Integral Word32 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Integral Word64 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Integral Word8 #

Since: base-2.1

Instance details

Defined in GHC.Internal.Word

Integral Integer #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Integral Natural #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Real

Integral Int #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

quot :: Int -> Int -> Int #

rem :: Int -> Int -> Int #

div :: Int -> Int -> Int #

mod :: Int -> Int -> Int #

quotRem :: Int -> Int -> (Int, Int) #

divMod :: Int -> Int -> (Int, Int) #

toInteger :: Int -> Integer #

Integral Word #

Since: base-2.1

Instance details

Defined in GHC.Internal.Real

Methods

quot :: Word -> Word -> Word #

rem :: Word -> Word -> Word #

div :: Word -> Word -> Word #

mod :: Word -> Word -> Word #

quotRem :: Word -> Word -> (Word, Word) #

divMod :: Word -> Word -> (Word, Word) #

toInteger :: Word -> Integer #

Integral a => Integral (Identity a) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Identity

Integral a => Integral (Const a b) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Const

Methods

quot :: Const a b -> Const a b -> Const a b #

rem :: Const a b -> Const a b -> Const a b #

div :: Const a b -> Const a b -> Const a b #

mod :: Const a b -> Const a b -> Const a b #

quotRem :: Const a b -> Const a b -> (Const a b, Const a b) #

divMod :: Const a b -> Const a b -> (Const a b, Const a b) #

toInteger :: Const a b -> Integer #

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:

recip gives the multiplicative inverse
x * recip x = recip x * x = fromInteger 1
Totality of toRational
toRational is total
Coherence with toRational
if the type also implements Real, then fromRational is a left inverse for toRational, i.e. fromRational (toRational i) = i

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

(/) :: a -> a -> a infixl 7 #

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

Instances details
Fractional CDouble # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Fractional CFloat # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Fractional Double #

This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.

>>> 0 == (-0 :: Double)
True
>>> recip 0 == recip (-0 :: Double)
False
>>> map (/ 0) [-1, 0, 1]
[-Infinity,NaN,Infinity]
>>> map (* 0) $ map (/ 0) [-1, 0, 1]
[NaN,NaN,NaN]

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Fractional Float #

This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.

>>> 0 == (-0 :: Float)
True
>>> recip 0 == recip (-0 :: Float)
False
>>> map (/ 0) [-1, 0, 1 :: Float]
[-Infinity,NaN,Infinity]
>>> map (* 0) $ map (/ 0) [-1, 0, 1 :: Float]
[NaN,NaN,NaN]

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Fractional a => Fractional (Identity a) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Identity

Fractional a => Fractional (Down a) #

Since: base-4.14.0.0

Instance details

Defined in GHC.Internal.Data.Ord

Methods

(/) :: Down a -> Down a -> Down a #

recip :: Down a -> Down a #

fromRational :: Rational -> Down a #

Integral a => Fractional (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

(/) :: Ratio a -> Ratio a -> Ratio a #

recip :: Ratio a -> Ratio a #

fromRational :: Rational -> Ratio a #

Fractional a => Fractional (Const a b) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Const

Methods

(/) :: Const a b -> Const a b -> Const a b #

recip :: Const a b -> Const a b #

fromRational :: Rational -> Const a b #

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; the even integer if x is equidistant between two integers

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

Instances details
RealFrac CDouble # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

properFraction :: Integral b => CDouble -> (b, CDouble) #

truncate :: Integral b => CDouble -> b #

round :: Integral b => CDouble -> b #

ceiling :: Integral b => CDouble -> b #

floor :: Integral b => CDouble -> b #

RealFrac CFloat # 
Instance details

Defined in GHC.Internal.Foreign.C.Types

Methods

properFraction :: Integral b => CFloat -> (b, CFloat) #

truncate :: Integral b => CFloat -> b #

round :: Integral b => CFloat -> b #

ceiling :: Integral b => CFloat -> b #

floor :: Integral b => CFloat -> b #

RealFrac Double #

Beware that results for non-finite arguments are garbage:

>>> [ f x | f <- [round, floor, ceiling], x <- [-1/0, 0/0, 1/0] ] :: [Int]
[0,0,0,0,0,0,0,0,0]
>>> map properFraction [-1/0, 0/0, 1/0] :: [(Int, Double)]
[(0,0.0),(0,0.0),(0,0.0)]

and get even more non-sensical if you ask for Integer instead of Int.

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Methods

properFraction :: Integral b => Double -> (b, Double) #

truncate :: Integral b => Double -> b #

round :: Integral b => Double -> b #

ceiling :: Integral b => Double -> b #

floor :: Integral b => Double -> b #

RealFrac Float #

Beware that results for non-finite arguments are garbage:

>>> [ f x | f <- [round, floor, ceiling], x <- [-1/0, 0/0, 1/0 :: Float] ] :: [Int]
[0,0,0,0,0,0,0,0,0]
>>> map properFraction [-1/0, 0/0, 1/0] :: [(Int, Float)]
[(0,0.0),(0,0.0),(0,0.0)]

and get even more non-sensical if you ask for Integer instead of Int.

Since: base-2.1

Instance details

Defined in GHC.Internal.Float

Methods

properFraction :: Integral b => Float -> (b, Float) #

truncate :: Integral b => Float -> b #

round :: Integral b => Float -> b #

ceiling :: Integral b => Float -> b #

floor :: Integral b => Float -> b #

RealFrac a => RealFrac (Identity a) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Identity

Methods

properFraction :: Integral b => Identity a -> (b, Identity a) #

truncate :: Integral b => Identity a -> b #

round :: Integral b => Identity a -> b #

ceiling :: Integral b => Identity a -> b #

floor :: Integral b => Identity a -> b #

RealFrac a => RealFrac (Down a) #

Since: base-4.14.0.0

Instance details

Defined in GHC.Internal.Data.Ord

Methods

properFraction :: Integral b => Down a -> (b, Down a) #

truncate :: Integral b => Down a -> b #

round :: Integral b => Down a -> b #

ceiling :: Integral b => Down a -> b #

floor :: Integral b => Down a -> b #

Integral a => RealFrac (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

properFraction :: Integral b => Ratio a -> (b, Ratio a) #

truncate :: Integral b => Ratio a -> b #

round :: Integral b => Ratio a -> b #

ceiling :: Integral b => Ratio a -> b #

floor :: Integral b => Ratio a -> b #

RealFrac a => RealFrac (Const a b) #

Since: base-4.9.0.0

Instance details

Defined in GHC.Internal.Data.Functor.Const

Methods

properFraction :: Integral b0 => Const a b -> (b0, Const a b) #

truncate :: Integral b0 => Const a b -> b0 #

round :: Integral b0 => Const a b -> b0 #

ceiling :: Integral b0 => Const a b -> b0 #

floor :: Integral b0 => Const a b -> b0 #

Conversion

fromIntegral :: (Integral a, Num b) => a -> b #

General coercion from Integral types.

WARNING: This function performs silent truncation if the result type is not at least as big as the argument's type.

realToFrac :: (Real a, Fractional b) => a -> b #

General coercion to Fractional types.

WARNING: This function goes through the Rational type, which does not have values for NaN for example. This means it does not round-trip.

For Double it also behaves differently with or without -O0:

Prelude> realToFrac nan -- With -O0
-Infinity
Prelude> realToFrac nan
NaN

Formatting

showSigned #

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.

Predicates

even :: Integral a => a -> Bool #

odd :: Integral a => a -> Bool #

Arithmetic

(^) :: (Num a, Integral b) => a -> b -> a infixr 8 #

raise a number to a non-negative integral power

(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 #

raise a number to an integral power

gcd :: Integral a => a -> a -> a #

gcd x y is the non-negative factor of both x 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 4 = 4. gcd 0 0 = 0. (That is, the common divisor that is "greatest" in the divisibility preordering.)

Note: Since for signed fixed-width integer types, abs minBound < 0, the result may be negative if one of the arguments is minBound (and necessarily is if the other is 0 or minBound) for such types.

lcm :: Integral a => a -> a -> a #

lcm x y is the smallest positive integer that both x and y divide.

Ratio

data Ratio 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

Instances details
Integral a => Lift (Ratio a :: Type) # 
Instance details

Defined in GHC.Internal.TH.Lift

Methods

lift :: Quote m => Ratio a -> m Exp #

liftTyped :: forall (m :: Type -> Type). Quote m => Ratio a -> Code m (Ratio a) #

Eq a => Eq (Ratio a) #

Since: base-2.1

Instance details

Defined in GHC.Internal.Real

Methods

(==) :: Ratio a -> Ratio a -> Bool #

(/=) :: Ratio a -> Ratio a -> Bool #

Integral a => Ord (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

compare :: Ratio a -> Ratio a -> Ordering #

(<) :: Ratio a -> Ratio a -> Bool #

(<=) :: Ratio a -> Ratio a -> Bool #

(>) :: Ratio a -> Ratio a -> Bool #

(>=) :: Ratio a -> Ratio a -> Bool #

max :: Ratio a -> Ratio a -> Ratio a #

min :: Ratio a -> Ratio a -> Ratio a #

(Data a, Integral a) => Data (Ratio a) #

Since: base-4.0.0.0

Instance details

Defined in GHC.Internal.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) #

Integral a => Enum (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

succ :: Ratio a -> Ratio a #

pred :: Ratio a -> Ratio a #

toEnum :: Int -> Ratio a #

fromEnum :: Ratio a -> Int #

enumFrom :: Ratio a -> [Ratio a] #

enumFromThen :: Ratio a -> Ratio a -> [Ratio a] #

enumFromTo :: Ratio a -> Ratio a -> [Ratio a] #

enumFromThenTo :: Ratio a -> Ratio a -> Ratio a -> [Ratio a] #

(Storable a, Integral a) => Storable (Ratio a) #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Foreign.Storable

Methods

sizeOf :: Ratio a -> Int #

alignment :: Ratio a -> Int #

peekElemOff :: Ptr (Ratio a) -> Int -> IO (Ratio a) #

pokeElemOff :: Ptr (Ratio a) -> Int -> Ratio a -> IO () #

peekByteOff :: Ptr b -> Int -> IO (Ratio a) #

pokeByteOff :: Ptr b -> Int -> Ratio a -> IO () #

peek :: Ptr (Ratio a) -> IO (Ratio a) #

poke :: Ptr (Ratio a) -> Ratio a -> IO () #

Integral a => Num (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

(+) :: Ratio a -> Ratio a -> Ratio a #

(-) :: Ratio a -> Ratio a -> Ratio a #

(*) :: Ratio a -> Ratio a -> Ratio a #

negate :: Ratio a -> Ratio a #

abs :: Ratio a -> Ratio a #

signum :: Ratio a -> Ratio a #

fromInteger :: Integer -> Ratio a #

(Integral a, Read a) => Read (Ratio a) #

Since: base-2.1

Instance details

Defined in GHC.Internal.Read

Integral a => Fractional (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

(/) :: Ratio a -> Ratio a -> Ratio a #

recip :: Ratio a -> Ratio a #

fromRational :: Rational -> Ratio a #

Integral a => Real (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

toRational :: Ratio a -> Rational #

Integral a => RealFrac (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

properFraction :: Integral b => Ratio a -> (b, Ratio a) #

truncate :: Integral b => Ratio a -> b #

round :: Integral b => Ratio a -> b #

ceiling :: Integral b => Ratio a -> b #

floor :: Integral b => Ratio a -> b #

Show a => Show (Ratio a) #

Since: base-2.0.1

Instance details

Defined in GHC.Internal.Real

Methods

showsPrec :: Int -> Ratio a -> ShowS #

show :: Ratio a -> String #

showList :: [Ratio a] -> ShowS #

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.

Enum helpers

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] #

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] #

Construction

(%) :: Integral a => a -> a -> Ratio a infixl 7 #

Forms the ratio of two integral numbers.

Projection

numerator :: 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 :: 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.

Operations

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.

Internal

(^%^) :: Integral a => Rational -> a -> Rational #

powImpl :: (Num a, Integral b) => a -> b -> a #

powImplAcc :: (Num a, Integral b) => a -> b -> a -> a #