| Copyright | (c) The University of Glasgow 1994-2002 |
|---|---|
| License | see libraries/base/LICENSE |
| Maintainer | ghc-devs@haskell.org |
| Stability | internal |
| Portability | non-portable (GHC Extensions) |
| Safe Haskell | Safe |
| Language | Haskell2010 |
GHC.Real
Synopsis
- 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
- fromIntegral :: (Integral a, Num b) => a -> b
- 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
- gcd :: Integral a => a -> a -> a
- lcm :: Integral a => a -> a -> a
- data Ratio a = !a :% !a
- type Rational = Ratio Integer
- infinity :: Rational
- notANumber :: Rational
- 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]
- (%) :: Integral a => a -> a -> Ratio a
- numerator :: Ratio a -> a
- denominator :: Ratio a -> a
- reduce :: Integral a => a -> a -> Ratio a
- ratioPrec :: Int
- ratioPrec1 :: Int
- divZeroError :: a
- ratioZeroDenominatorError :: a
- overflowError :: a
- underflowError :: a
- mkRationalBase2 :: Rational -> Integer -> Rational
- mkRationalBase10 :: Rational -> Integer -> Rational
- data FractionalExponentBase
- (^%^) :: Integral a => Rational -> a -> Rational
- (^^%^^) :: Integral a => Rational -> a -> Rational
- mkRationalWithExponentBase :: Rational -> Integer -> FractionalExponentBase -> Rational
- powImpl :: (Num a, Integral b) => a -> b -> a
- powImplAcc :: (Num a, Integral b) => a -> b -> a -> a
Classes
class (Num a, Ord a) => Real a where Source #
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, thenfromRationalis a left inverse fortoRational, 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 Source #
Rational equivalent of its real argument with full precision.
Instances
| Real CBool Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CBool -> Rational Source # | |
| Real CChar Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CChar -> Rational Source # | |
| Real CClock Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CClock -> Rational Source # | |
| Real CDouble Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CDouble -> Rational Source # | |
| Real CFloat Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CFloat -> Rational Source # | |
| Real CInt Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CInt -> Rational Source # | |
| Real CIntMax Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CIntMax -> Rational Source # | |
| Real CIntPtr Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CIntPtr -> Rational Source # | |
| Real CLLong Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CLLong -> Rational Source # | |
| Real CLong Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CLong -> Rational Source # | |
| Real CPtrdiff Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CPtrdiff -> Rational Source # | |
| Real CSChar Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CSChar -> Rational Source # | |
| Real CSUSeconds Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CSUSeconds -> Rational Source # | |
| Real CShort Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CShort -> Rational Source # | |
| Real CSigAtomic Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CSigAtomic -> Rational Source # | |
| Real CSize Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CSize -> Rational Source # | |
| Real CTime Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CTime -> Rational Source # | |
| Real CUChar Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CUChar -> Rational Source # | |
| Real CUInt Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CUInt -> Rational Source # | |
| Real CUIntMax Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CUIntMax -> Rational Source # | |
| Real CUIntPtr Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CUIntPtr -> Rational Source # | |
| Real CULLong Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CULLong -> Rational Source # | |
| Real CULong Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CULong -> Rational Source # | |
| Real CUSeconds Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CUSeconds -> Rational Source # | |
| Real CUShort Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CUShort -> Rational Source # | |
| Real CWchar Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods toRational :: CWchar -> Rational Source # | |
| Real IntPtr Source # | |
Defined in GHC.Internal.Foreign.Ptr Methods toRational :: IntPtr -> Rational Source # | |
| Real WordPtr Source # | |
Defined in GHC.Internal.Foreign.Ptr Methods toRational :: WordPtr -> Rational Source # | |
| Real HalfWord Source # | |
Defined in GHC.Internal.Heap.InfoTable.Types Methods toRational :: HalfWord -> Rational Source # | |
| Real Int16 Source # | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int16 -> Rational Source # | |
| Real Int32 Source # | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int32 -> Rational Source # | |
| Real Int64 Source # | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int64 -> Rational Source # | |
| Real Int8 Source # | Since: base-2.1 |
Defined in GHC.Internal.Int Methods toRational :: Int8 -> Rational Source # | |
| Real ByteOffset Source # | |
Defined in GHC.Internal.Stack.Constants Methods toRational :: ByteOffset -> Rational Source # | |
| Real WordOffset Source # | |
Defined in GHC.Internal.Stack.Constants Methods toRational :: WordOffset -> Rational Source # | |
| Real ByteOffset Source # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods toRational :: ByteOffset -> Rational Source # | |
| Real WordOffset Source # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods toRational :: WordOffset -> Rational Source # | |
| Real CBlkCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CBlkCnt -> Rational Source # | |
| Real CBlkSize Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CBlkSize -> Rational Source # | |
| Real CCc Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CCc -> Rational Source # | |
| Real CClockId Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CClockId -> Rational Source # | |
| Real CDev Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CDev -> Rational Source # | |
| Real CFsBlkCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CFsBlkCnt -> Rational Source # | |
| Real CFsFilCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CFsFilCnt -> Rational Source # | |
| Real CGid Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CGid -> Rational Source # | |
| Real CId Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CId -> Rational Source # | |
| Real CIno Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CIno -> Rational Source # | |
| Real CKey Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CKey -> Rational Source # | |
| Real CMode Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CMode -> Rational Source # | |
| Real CNfds Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CNfds -> Rational Source # | |
| Real CNlink Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CNlink -> Rational Source # | |
| Real COff Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: COff -> Rational Source # | |
| Real CPid Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CPid -> Rational Source # | |
| Real CRLim Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CRLim -> Rational Source # | |
| Real CSocklen Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CSocklen -> Rational Source # | |
| Real CSpeed Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CSpeed -> Rational Source # | |
| Real CSsize Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CSsize -> Rational Source # | |
| Real CTcflag Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CTcflag -> Rational Source # | |
| Real CUid Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: CUid -> Rational Source # | |
| Real Fd Source # | |
Defined in GHC.Internal.System.Posix.Types Methods toRational :: Fd -> Rational Source # | |
| Real Word16 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word16 -> Rational Source # | |
| Real Word32 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word32 -> Rational Source # | |
| Real Word64 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word64 -> Rational Source # | |
| Real Word8 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word Methods toRational :: Word8 -> Rational Source # | |
| Real Integer Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Integer -> Rational Source # | |
| Real Natural Source # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real Methods toRational :: Natural -> Rational Source # | |
| Real Double Source # | Beware that
Since: base-2.1 |
Defined in GHC.Internal.Float Methods toRational :: Double -> Rational Source # | |
| Real Float Source # | Beware that
Since: base-2.1 |
Defined in GHC.Internal.Float Methods toRational :: Float -> Rational Source # | |
| Real Int Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Int -> Rational Source # | |
| Real Word Source # | Since: base-2.1 |
Defined in GHC.Internal.Real Methods toRational :: Word -> Rational Source # | |
| Real a => Real (Identity a) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods toRational :: Identity a -> Rational Source # | |
| Real a => Real (Down a) Source # | Since: base-4.14.0.0 |
Defined in GHC.Internal.Data.Ord Methods toRational :: Down a -> Rational Source # | |
| Integral a => Real (Ratio a) Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Ratio a -> Rational Source # | |
| HasResolution a => Real (Fixed a) Source # | Since: base-2.1 |
Defined in Data.Fixed Methods toRational :: Fixed a -> Rational Source # | |
| Real a => Real (Const a b) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods toRational :: Const a b -> Rational Source # | |
| Real (f (g a)) => Real (Compose f g a) Source # | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods toRational :: Compose f g a -> Rational Source # | |
class (Real a, Enum a) => Integral a where Source #
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 ywithrem x y=fromInteger 0org (rem x y)<g yx=y * div x y + mod x ywithmod x y=fromInteger 0orf (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.
Methods
quot :: a -> a -> a infixl 7 Source #
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 Source #
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 Source #
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 Source #
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) Source #
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) Source #
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 Source #
Conversion to Integer.
Instances
| Integral CBool Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CChar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CInt Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CIntMax Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CIntMax -> CIntMax -> CIntMax Source # rem :: CIntMax -> CIntMax -> CIntMax Source # div :: CIntMax -> CIntMax -> CIntMax Source # mod :: CIntMax -> CIntMax -> CIntMax Source # quotRem :: CIntMax -> CIntMax -> (CIntMax, CIntMax) Source # | |
| Integral CIntPtr Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CIntPtr -> CIntPtr -> CIntPtr Source # rem :: CIntPtr -> CIntPtr -> CIntPtr Source # div :: CIntPtr -> CIntPtr -> CIntPtr Source # mod :: CIntPtr -> CIntPtr -> CIntPtr Source # quotRem :: CIntPtr -> CIntPtr -> (CIntPtr, CIntPtr) Source # | |
| Integral CLLong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CLong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CPtrdiff Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # rem :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # div :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # mod :: CPtrdiff -> CPtrdiff -> CPtrdiff Source # quotRem :: CPtrdiff -> CPtrdiff -> (CPtrdiff, CPtrdiff) Source # divMod :: CPtrdiff -> CPtrdiff -> (CPtrdiff, CPtrdiff) Source # | |
| Integral CSChar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CShort Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CSigAtomic Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # rem :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # div :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # mod :: CSigAtomic -> CSigAtomic -> CSigAtomic Source # quotRem :: CSigAtomic -> CSigAtomic -> (CSigAtomic, CSigAtomic) Source # divMod :: CSigAtomic -> CSigAtomic -> (CSigAtomic, CSigAtomic) Source # toInteger :: CSigAtomic -> Integer Source # | |
| Integral CSize Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CUChar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CUInt Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CUIntMax Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CUIntMax -> CUIntMax -> CUIntMax Source # rem :: CUIntMax -> CUIntMax -> CUIntMax Source # div :: CUIntMax -> CUIntMax -> CUIntMax Source # mod :: CUIntMax -> CUIntMax -> CUIntMax Source # quotRem :: CUIntMax -> CUIntMax -> (CUIntMax, CUIntMax) Source # divMod :: CUIntMax -> CUIntMax -> (CUIntMax, CUIntMax) Source # | |
| Integral CUIntPtr Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # rem :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # div :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # mod :: CUIntPtr -> CUIntPtr -> CUIntPtr Source # quotRem :: CUIntPtr -> CUIntPtr -> (CUIntPtr, CUIntPtr) Source # divMod :: CUIntPtr -> CUIntPtr -> (CUIntPtr, CUIntPtr) Source # | |
| Integral CULLong Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CULLong -> CULLong -> CULLong Source # rem :: CULLong -> CULLong -> CULLong Source # div :: CULLong -> CULLong -> CULLong Source # mod :: CULLong -> CULLong -> CULLong Source # quotRem :: CULLong -> CULLong -> (CULLong, CULLong) Source # | |
| Integral CULong Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral CUShort Source # | |
Defined in GHC.Internal.Foreign.C.Types Methods quot :: CUShort -> CUShort -> CUShort Source # rem :: CUShort -> CUShort -> CUShort Source # div :: CUShort -> CUShort -> CUShort Source # mod :: CUShort -> CUShort -> CUShort Source # quotRem :: CUShort -> CUShort -> (CUShort, CUShort) Source # | |
| Integral CWchar Source # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Integral IntPtr Source # | |
Defined in GHC.Internal.Foreign.Ptr | |
| Integral WordPtr Source # | |
Defined in GHC.Internal.Foreign.Ptr Methods quot :: WordPtr -> WordPtr -> WordPtr Source # rem :: WordPtr -> WordPtr -> WordPtr Source # div :: WordPtr -> WordPtr -> WordPtr Source # mod :: WordPtr -> WordPtr -> WordPtr Source # quotRem :: WordPtr -> WordPtr -> (WordPtr, WordPtr) Source # | |
| Integral HalfWord Source # | |
Defined in GHC.Internal.Heap.InfoTable.Types Methods quot :: HalfWord -> HalfWord -> HalfWord Source # rem :: HalfWord -> HalfWord -> HalfWord Source # div :: HalfWord -> HalfWord -> HalfWord Source # mod :: HalfWord -> HalfWord -> HalfWord Source # quotRem :: HalfWord -> HalfWord -> (HalfWord, HalfWord) Source # divMod :: HalfWord -> HalfWord -> (HalfWord, HalfWord) Source # | |
| Integral Int16 Source # | Since: base-2.1 |
| Integral Int32 Source # | Since: base-2.1 |
| Integral Int64 Source # | Since: base-2.1 |
| Integral Int8 Source # | Since: base-2.1 |
Defined in GHC.Internal.Int | |
| Integral ByteOffset Source # | |
Defined in GHC.Internal.Stack.Constants Methods quot :: ByteOffset -> ByteOffset -> ByteOffset Source # rem :: ByteOffset -> ByteOffset -> ByteOffset Source # div :: ByteOffset -> ByteOffset -> ByteOffset Source # mod :: ByteOffset -> ByteOffset -> ByteOffset Source # quotRem :: ByteOffset -> ByteOffset -> (ByteOffset, ByteOffset) Source # divMod :: ByteOffset -> ByteOffset -> (ByteOffset, ByteOffset) Source # | |
| Integral WordOffset Source # | |
Defined in GHC.Internal.Stack.Constants Methods quot :: WordOffset -> WordOffset -> WordOffset Source # rem :: WordOffset -> WordOffset -> WordOffset Source # div :: WordOffset -> WordOffset -> WordOffset Source # mod :: WordOffset -> WordOffset -> WordOffset Source # quotRem :: WordOffset -> WordOffset -> (WordOffset, WordOffset) Source # divMod :: WordOffset -> WordOffset -> (WordOffset, WordOffset) Source # | |
| Integral ByteOffset Source # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods quot :: ByteOffset -> ByteOffset -> ByteOffset Source # rem :: ByteOffset -> ByteOffset -> ByteOffset Source # div :: ByteOffset -> ByteOffset -> ByteOffset Source # mod :: ByteOffset -> ByteOffset -> ByteOffset Source # quotRem :: ByteOffset -> ByteOffset -> (ByteOffset, ByteOffset) Source # divMod :: ByteOffset -> ByteOffset -> (ByteOffset, ByteOffset) Source # | |
| Integral WordOffset Source # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods quot :: WordOffset -> WordOffset -> WordOffset Source # rem :: WordOffset -> WordOffset -> WordOffset Source # div :: WordOffset -> WordOffset -> WordOffset Source # mod :: WordOffset -> WordOffset -> WordOffset Source # quotRem :: WordOffset -> WordOffset -> (WordOffset, WordOffset) Source # divMod :: WordOffset -> WordOffset -> (WordOffset, WordOffset) Source # | |
| Integral CBlkCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CBlkCnt -> CBlkCnt -> CBlkCnt Source # rem :: CBlkCnt -> CBlkCnt -> CBlkCnt Source # div :: CBlkCnt -> CBlkCnt -> CBlkCnt Source # mod :: CBlkCnt -> CBlkCnt -> CBlkCnt Source # quotRem :: CBlkCnt -> CBlkCnt -> (CBlkCnt, CBlkCnt) Source # | |
| Integral CBlkSize Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CBlkSize -> CBlkSize -> CBlkSize Source # rem :: CBlkSize -> CBlkSize -> CBlkSize Source # div :: CBlkSize -> CBlkSize -> CBlkSize Source # mod :: CBlkSize -> CBlkSize -> CBlkSize Source # quotRem :: CBlkSize -> CBlkSize -> (CBlkSize, CBlkSize) Source # divMod :: CBlkSize -> CBlkSize -> (CBlkSize, CBlkSize) Source # | |
| Integral CClockId Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CClockId -> CClockId -> CClockId Source # rem :: CClockId -> CClockId -> CClockId Source # div :: CClockId -> CClockId -> CClockId Source # mod :: CClockId -> CClockId -> CClockId Source # quotRem :: CClockId -> CClockId -> (CClockId, CClockId) Source # divMod :: CClockId -> CClockId -> (CClockId, CClockId) Source # | |
| Integral CDev Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CFsBlkCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # rem :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # div :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # mod :: CFsBlkCnt -> CFsBlkCnt -> CFsBlkCnt Source # quotRem :: CFsBlkCnt -> CFsBlkCnt -> (CFsBlkCnt, CFsBlkCnt) Source # divMod :: CFsBlkCnt -> CFsBlkCnt -> (CFsBlkCnt, CFsBlkCnt) Source # | |
| Integral CFsFilCnt Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # rem :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # div :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # mod :: CFsFilCnt -> CFsFilCnt -> CFsFilCnt Source # quotRem :: CFsFilCnt -> CFsFilCnt -> (CFsFilCnt, CFsFilCnt) Source # divMod :: CFsFilCnt -> CFsFilCnt -> (CFsFilCnt, CFsFilCnt) Source # | |
| Integral CGid Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CId Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CIno Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CKey Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CMode Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CNfds Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CNlink Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral COff Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CPid Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CRLim Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CSocklen Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CSocklen -> CSocklen -> CSocklen Source # rem :: CSocklen -> CSocklen -> CSocklen Source # div :: CSocklen -> CSocklen -> CSocklen Source # mod :: CSocklen -> CSocklen -> CSocklen Source # quotRem :: CSocklen -> CSocklen -> (CSocklen, CSocklen) Source # divMod :: CSocklen -> CSocklen -> (CSocklen, CSocklen) Source # | |
| Integral CSsize Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral CTcflag Source # | |
Defined in GHC.Internal.System.Posix.Types Methods quot :: CTcflag -> CTcflag -> CTcflag Source # rem :: CTcflag -> CTcflag -> CTcflag Source # div :: CTcflag -> CTcflag -> CTcflag Source # mod :: CTcflag -> CTcflag -> CTcflag Source # quotRem :: CTcflag -> CTcflag -> (CTcflag, CTcflag) Source # | |
| Integral CUid Source # | |
Defined in GHC.Internal.System.Posix.Types | |
| Integral Fd Source # | |
| Integral Word16 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Integral Word32 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Integral Word64 Source # | Since: base-2.1 |
Defined in GHC.Internal.Word | |
| Integral Word8 Source # | Since: base-2.1 |
| Integral Integer Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods quot :: Integer -> Integer -> Integer Source # rem :: Integer -> Integer -> Integer Source # div :: Integer -> Integer -> Integer Source # mod :: Integer -> Integer -> Integer Source # quotRem :: Integer -> Integer -> (Integer, Integer) Source # | |
| Integral Natural Source # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real Methods quot :: Natural -> Natural -> Natural Source # rem :: Natural -> Natural -> Natural Source # div :: Natural -> Natural -> Natural Source # mod :: Natural -> Natural -> Natural Source # quotRem :: Natural -> Natural -> (Natural, Natural) Source # | |
| Integral Int Source # | Since: base-2.0.1 |
| Integral Word Source # | Since: base-2.1 |
Defined in GHC.Internal.Real | |
| Integral a => Integral (Identity a) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity Methods quot :: Identity a -> Identity a -> Identity a Source # rem :: Identity a -> Identity a -> Identity a Source # div :: Identity a -> Identity a -> Identity a Source # mod :: Identity a -> Identity a -> Identity a Source # quotRem :: Identity a -> Identity a -> (Identity a, Identity a) Source # divMod :: Identity a -> Identity a -> (Identity a, Identity a) Source # | |
| Integral a => Integral (Const a b) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const Methods quot :: Const a b -> Const a b -> Const a b Source # rem :: Const a b -> Const a b -> Const a b Source # div :: Const a b -> Const a b -> Const a b Source # mod :: Const a b -> Const a b -> Const a b Source # quotRem :: Const a b -> Const a b -> (Const a b, Const a b) Source # divMod :: Const a b -> Const a b -> (Const a b, Const a b) Source # | |
| Integral (f (g a)) => Integral (Compose f g a) Source # | Since: base-4.19.0.0 |
Defined in Data.Functor.Compose Methods quot :: Compose f g a -> Compose f g a -> Compose f g a Source # rem :: Compose f g a -> Compose f g a -> Compose f g a Source # div :: Compose f g a -> Compose f g a -> Compose f g a Source # mod :: Compose f g a -> Compose f g a -> Compose f g a Source # quotRem :: Compose f g a -> Compose f g a -> (Compose f g a, Compose f g a) Source # divMod :: Compose f g a -> Compose f g a -> (Compose f g a, Compose f g a) Source # | |
class Num a => Fractional a where Source #
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 inversex * recip x=recip x * x=fromInteger 1- Totality of
toRational toRationalis total- Coherence with
toRational - if the type also implements
Real, thenfromRationalis a left inverse fortoRational, 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 Source #
Fractional division.
Reciprocal fraction.
fromRational :: Rational -> a Source #
Conversion from a Rational (that is ).
A floating literal stands for an application of Ratio IntegerfromRational
to a value of type Rational, so such literals have type
(.Fractional a) => a
Instances
| Fractional CDouble Source # | |
| Fractional CFloat Source # | |
| Fractional Double Source # | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.
Since: base-2.1 |
| Fractional Float Source # | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero.
Since: base-2.1 |
| RealFloat a => Fractional (Complex a) Source # | Since: base-2.1 |
| Fractional a => Fractional (Identity a) Source # | Since: base-4.9.0.0 |
| Fractional a => Fractional (Down a) Source # | Since: base-4.14.0.0 |
| Integral a => Fractional (Ratio a) Source # | Since: base-2.0.1 |
| HasResolution a => Fractional (Fixed a) Source # | Since: base-2.1 |
| Fractional a => Fractional (Op a b) Source # | |
| Fractional a => Fractional (Const a b) Source # | Since: base-4.9.0.0 |
| Fractional (f (g a)) => Fractional (Compose f g a) Source # | Since: base-4.20.0.0 |
class (Real a, Fractional a) => RealFrac a where Source #
Extracting components of fractions.
Minimal complete definition
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:
nis an integral number with the same sign asx; andfis a fraction with the same type and sign asx, and with absolute value less than1.
The default definitions of the ceiling, floor, truncate
and round functions are in terms of properFraction.
truncate :: Integral b => a -> b Source #
returns the integer nearest truncate xx between zero and x
round :: Integral b => a -> b Source #
returns the nearest integer to round xx;
the even integer if x is equidistant between two integers
ceiling :: Integral b => a -> b Source #
returns the least integer not less than ceiling xx
floor :: Integral b => a -> b Source #
returns the greatest integer not greater than floor xx
Instances
| RealFrac CDouble Source # | |
| RealFrac CFloat Source # | |
| RealFrac Double Source # | Beware that results for non-finite arguments are garbage:
and get even more non-sensical if you ask for Since: base-2.1 |
| RealFrac Float Source # | Beware that results for non-finite arguments are garbage:
and get even more non-sensical if you ask for Since: base-2.1 |
| RealFrac a => RealFrac (Identity a) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity | |
| RealFrac a => RealFrac (Down a) Source # | Since: base-4.14.0.0 |
| Integral a => RealFrac (Ratio a) Source # | Since: base-2.0.1 |
| HasResolution a => RealFrac (Fixed a) Source # | Since: base-2.1 |
| RealFrac a => RealFrac (Const a b) Source # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const | |
| RealFrac (f (g a)) => RealFrac (Compose f g a) Source # | Since: base-4.20.0.0 |
Defined in Data.Functor.Compose | |
Conversion
fromIntegral :: (Integral a, Num b) => a -> b Source #
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 Source #
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 Source #
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
Arithmetic
(^) :: (Num a, Integral b) => a -> b -> a infixr 8 Source #
raise a number to a non-negative integral power
(^^) :: (Fractional a, Integral b) => a -> b -> a infixr 8 Source #
raise a number to an integral power
gcd :: Integral a => a -> a -> a Source #
is the non-negative factor of both gcd x yx 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 44. = gcd 0 00.
(That is, the common divisor that is "greatest" in the divisibility
preordering.)
Note: Since for signed fixed-width integer types, ,
the result may be negative if one of the arguments is abs minBound < 0 (and
necessarily is if the other is minBound0 or ) for such types.minBound
lcm :: Integral a => a -> a -> a Source #
is the smallest positive integer that both lcm x yx and y divide.
Ratio
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
| Integral a => Lift (Ratio a :: Type) Source # | |
| Eq a => Eq (Ratio a) Source # | Since: base-2.1 |
| Integral a => Ord (Ratio a) Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real | |
| (Data a, Integral a) => Data (Ratio a) Source # | Since: base-4.0.0.0 |
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) Source # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c (Ratio a) Source # toConstr :: Ratio a -> Constr Source # dataTypeOf :: Ratio a -> DataType Source # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c (Ratio a)) Source # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c (Ratio a)) Source # gmapT :: (forall b. Data b => b -> b) -> Ratio a -> Ratio a Source # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r Source # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Ratio a -> r Source # gmapQ :: (forall d. Data d => d -> u) -> Ratio a -> [u] Source # gmapQi :: Int -> (forall d. Data d => d -> u) -> Ratio a -> u Source # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Ratio a -> m (Ratio a) Source # | |
| Integral a => Enum (Ratio a) Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods succ :: Ratio a -> Ratio a Source # pred :: Ratio a -> Ratio a Source # toEnum :: Int -> Ratio a Source # fromEnum :: Ratio a -> Int Source # enumFrom :: Ratio a -> [Ratio a] Source # enumFromThen :: Ratio a -> Ratio a -> [Ratio a] Source # enumFromTo :: Ratio a -> Ratio a -> [Ratio a] Source # enumFromThenTo :: Ratio a -> Ratio a -> Ratio a -> [Ratio a] Source # | |
| (Storable a, Integral a) => Storable (Ratio a) Source # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Foreign.Storable Methods sizeOf :: Ratio a -> Int Source # alignment :: Ratio a -> Int Source # peekElemOff :: Ptr (Ratio a) -> Int -> IO (Ratio a) Source # pokeElemOff :: Ptr (Ratio a) -> Int -> Ratio a -> IO () Source # peekByteOff :: Ptr b -> Int -> IO (Ratio a) Source # pokeByteOff :: Ptr b -> Int -> Ratio a -> IO () Source # | |
| Integral a => Num (Ratio a) Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real | |
| (Integral a, Read a) => Read (Ratio a) Source # | Since: base-2.1 |
| Integral a => Fractional (Ratio a) Source # | Since: base-2.0.1 |
| Integral a => Real (Ratio a) Source # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Ratio a -> Rational Source # | |
| Integral a => RealFrac (Ratio a) Source # | Since: base-2.0.1 |
| Show a => Show (Ratio a) Source # | Since: base-2.0.1 |
notANumber :: Rational Source #
Enum helpers
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 #
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 #
Construction
Projection
numerator :: Ratio a -> a Source #
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 Source #
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 Source #
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
ratioPrec1 :: Int Source #
divZeroError :: a Source #
ratioZeroDenominatorError :: a Source #
overflowError :: a Source #
underflowError :: a Source #
mkRationalBase2 :: Rational -> Integer -> Rational Source #
mkRationalBase10 :: Rational -> Integer -> Rational Source #
data FractionalExponentBase Source #
Instances
| Show FractionalExponentBase Source # | |
Defined in GHC.Internal.Real Methods showsPrec :: Int -> FractionalExponentBase -> ShowS Source # show :: FractionalExponentBase -> String Source # showList :: [FractionalExponentBase] -> ShowS Source # | |
mkRationalWithExponentBase :: Rational -> Integer -> FractionalExponentBase -> Rational Source #
powImplAcc :: (Num a, Integral b) => a -> b -> a -> a Source #