| 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 | Trustworthy |
| Language | Haskell2010 |
GHC.Internal.Num
Synopsis
- class Num a where
- subtract :: Num a => a -> a -> a
- quotRemInteger :: Integer -> Integer -> (# Integer, Integer #)
- module GHC.Internal.Bignum.Integer
- module GHC.Internal.Bignum.Natural
- data Natural
- data Integer
Documentation
Basic numeric class.
The Haskell Report defines no laws for Num. However, ( and +)( are
customarily expected to define a ring and have the following properties:*)
- Associativity of
(+) (x + y) + z=x + (y + z)- Commutativity of
(+) x + y=y + xis the additive identityfromInteger0x + fromInteger 0=xnegategives the additive inversex + negate x=fromInteger 0- Associativity of
(*) (x * y) * z=x * (y * z)is the multiplicative identityfromInteger1x * fromInteger 1=xandfromInteger 1 * x=x- Distributivity of
(with respect to*)(+) a * (b + c)=(a * b) + (a * c)and(b + c) * a=(b * a) + (c * a)- Coherence with
toInteger - if the type also implements
Integral, thenfromIntegeris a left inverse fortoInteger, i.e.fromInteger (toInteger i) == i
Note that it isn't customarily expected that a type instance of both Num
and Ord implement an ordered ring. Indeed, in base only Integer and
Rational do.
Methods
Unary negation.
Absolute value.
Sign of a number.
The functions abs and signum should satisfy the law:
abs x * signum x == x
For real numbers, the signum is either -1 (negative), 0 (zero)
or 1 (positive).
fromInteger :: Integer -> a #
Conversion from an Integer.
An integer literal represents the application of the function
fromInteger to the appropriate value of type Integer,
so such literals have type (.Num a) => a
Instances
| Num CBool # | |
| Num CChar # | |
| Num CClock # | |
| Num CDouble # | |
| Num CFloat # | |
| Num CInt # | |
| Num CIntMax # | |
| Num CIntPtr # | |
| Num CLLong # | |
| Num CLong # | |
| Num CPtrdiff # | |
| Num CSChar # | |
| Num CSUSeconds # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CSUSeconds -> CSUSeconds -> CSUSeconds # (-) :: CSUSeconds -> CSUSeconds -> CSUSeconds # (*) :: CSUSeconds -> CSUSeconds -> CSUSeconds # negate :: CSUSeconds -> CSUSeconds # abs :: CSUSeconds -> CSUSeconds # signum :: CSUSeconds -> CSUSeconds # fromInteger :: Integer -> CSUSeconds # | |
| Num CShort # | |
| Num CSigAtomic # | |
Defined in GHC.Internal.Foreign.C.Types Methods (+) :: CSigAtomic -> CSigAtomic -> CSigAtomic # (-) :: CSigAtomic -> CSigAtomic -> CSigAtomic # (*) :: CSigAtomic -> CSigAtomic -> CSigAtomic # negate :: CSigAtomic -> CSigAtomic # abs :: CSigAtomic -> CSigAtomic # signum :: CSigAtomic -> CSigAtomic # fromInteger :: Integer -> CSigAtomic # | |
| Num CSize # | |
| Num CTime # | |
| Num CUChar # | |
| Num CUInt # | |
| Num CUIntMax # | |
| Num CUIntPtr # | |
| Num CULLong # | |
| Num CULong # | |
| Num CUSeconds # | |
Defined in GHC.Internal.Foreign.C.Types | |
| Num CUShort # | |
| Num CWchar # | |
| Num IntPtr # | |
| Num WordPtr # | |
| Num HalfWord # | |
Defined in GHC.Internal.Heap.InfoTable.Types | |
| Num Int16 # | Since: base-2.1 |
| Num Int32 # | Since: base-2.1 |
| Num Int64 # | Since: base-2.1 |
| Num Int8 # | Since: base-2.1 |
| Num ByteOffset # | |
Defined in GHC.Internal.Stack.Constants Methods (+) :: ByteOffset -> ByteOffset -> ByteOffset # (-) :: ByteOffset -> ByteOffset -> ByteOffset # (*) :: ByteOffset -> ByteOffset -> ByteOffset # negate :: ByteOffset -> ByteOffset # abs :: ByteOffset -> ByteOffset # signum :: ByteOffset -> ByteOffset # fromInteger :: Integer -> ByteOffset # | |
| Num WordOffset # | |
Defined in GHC.Internal.Stack.Constants Methods (+) :: WordOffset -> WordOffset -> WordOffset # (-) :: WordOffset -> WordOffset -> WordOffset # (*) :: WordOffset -> WordOffset -> WordOffset # negate :: WordOffset -> WordOffset # abs :: WordOffset -> WordOffset # signum :: WordOffset -> WordOffset # fromInteger :: Integer -> WordOffset # | |
| Num ByteOffset # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods (+) :: ByteOffset -> ByteOffset -> ByteOffset # (-) :: ByteOffset -> ByteOffset -> ByteOffset # (*) :: ByteOffset -> ByteOffset -> ByteOffset # negate :: ByteOffset -> ByteOffset # abs :: ByteOffset -> ByteOffset # signum :: ByteOffset -> ByteOffset # fromInteger :: Integer -> ByteOffset # | |
| Num WordOffset # | |
Defined in GHC.Internal.Stack.ConstantsProf Methods (+) :: WordOffset -> WordOffset -> WordOffset # (-) :: WordOffset -> WordOffset -> WordOffset # (*) :: WordOffset -> WordOffset -> WordOffset # negate :: WordOffset -> WordOffset # abs :: WordOffset -> WordOffset # signum :: WordOffset -> WordOffset # fromInteger :: Integer -> WordOffset # | |
| Num CBlkCnt # | |
| Num CBlkSize # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CCc # | |
| Num CClockId # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CDev # | |
| Num CFsBlkCnt # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CFsFilCnt # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CGid # | |
| Num CId # | |
| Num CIno # | |
| Num CKey # | |
| Num CMode # | |
| Num CNfds # | |
| Num CNlink # | |
| Num COff # | |
| Num CPid # | |
| Num CRLim # | |
| Num CSocklen # | |
Defined in GHC.Internal.System.Posix.Types | |
| Num CSpeed # | |
| Num CSsize # | |
| Num CTcflag # | |
| Num CUid # | |
| Num Fd # | |
| Num Word16 # | Since: base-2.1 |
| Num Word32 # | Since: base-2.1 |
| Num Word64 # | Since: base-2.1 |
| Num Word8 # | Since: base-2.1 |
| Num Integer # | Since: base-2.1 |
| Num Natural # | Note that Since: base-4.8.0.0 |
| Num Double # | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:
Since: base-2.1 |
| Num Float # | This instance implements IEEE 754 standard with all its usual pitfalls about NaN, infinities and negative zero. Neither addition nor multiplication are associative or distributive:
Since: base-2.1 |
| Num Int # | Since: base-2.1 |
| Num Word # | Since: base-2.1 |
| Num a => Num (Identity a) # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Identity | |
| Num a => Num (Down a) # | Since: base-4.11.0.0 |
| Num a => Num (Product a) # | Since: base-4.7.0.0 |
Defined in GHC.Internal.Data.Semigroup.Internal | |
| Num a => Num (Sum a) # | Since: base-4.7.0.0 |
| Integral a => Num (Ratio a) # | Since: base-2.0.1 |
| Num a => Num (Const a b) # | Since: base-4.9.0.0 |
Defined in GHC.Internal.Data.Functor.Const | |
| (Applicative f, Num a) => Num (Ap f a) # | Note that even if the underlying Commutativity:
Additive inverse:
Distributivity:
Since: base-4.12.0.0 |
| Num (f a) => Num (Alt f a) # | Since: base-4.8.0.0 |
quotRemInteger :: Integer -> Integer -> (# Integer, Integer #) #
Deprecated: Use integerQuotRem# instead
module GHC.Internal.Bignum.Integer
module GHC.Internal.Bignum.Natural
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS constructor
Instances
| Bits Natural # | Since: base-4.8.0 |
Defined in GHC.Internal.Bits Methods (.&.) :: Natural -> Natural -> Natural # (.|.) :: Natural -> Natural -> Natural # xor :: Natural -> Natural -> Natural # complement :: Natural -> Natural # shift :: Natural -> Int -> Natural # rotate :: Natural -> Int -> Natural # setBit :: Natural -> Int -> Natural # clearBit :: Natural -> Int -> Natural # complementBit :: Natural -> Int -> Natural # testBit :: Natural -> Int -> Bool # bitSizeMaybe :: Natural -> Maybe Int # shiftL :: Natural -> Int -> Natural # unsafeShiftL :: Natural -> Int -> Natural # shiftR :: Natural -> Int -> Natural # unsafeShiftR :: Natural -> Int -> Natural # rotateL :: Natural -> Int -> Natural # | |
| Eq Natural # | |
| Ord Natural # | |
Defined in GHC.Internal.Bignum.Natural | |
| Data Natural # | Since: base-4.8.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) -> Natural -> c Natural # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Natural # toConstr :: Natural -> Constr # dataTypeOf :: Natural -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Natural) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Natural) # gmapT :: (forall b. Data b => b -> b) -> Natural -> Natural # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r # gmapQ :: (forall d. Data d => d -> u) -> Natural -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Natural -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Natural -> m Natural # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural # | |
| Enum Natural # | Since: base-4.8.0.0 |
| Ix Natural # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Ix | |
| Num Natural # | Note that Since: base-4.8.0.0 |
| Read Natural # | Since: base-4.8.0.0 |
| Integral Natural # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real | |
| Real Natural # | Since: base-4.8.0.0 |
Defined in GHC.Internal.Real Methods toRational :: Natural -> Rational # | |
| Show Natural # | Since: base-4.8.0.0 |
| TestCoercion SNat # | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| TestEquality SNat # | Since: base-4.18.0.0 |
Defined in GHC.Internal.TypeNats | |
| Lift Natural # | |
| type Compare (a :: Natural) (b :: Natural) # | |
Defined in GHC.Internal.Data.Type.Ord | |
Arbitrary precision integers. In contrast with fixed-size integral types
such as Int, the Integer type represents the entire infinite range of
integers.
Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.
If the value is small (i.e., fits into an Int), the IS constructor is
used. Otherwise IP and IN constructors are used to store a BigNat
representing the positive or the negative value magnitude, respectively.
Invariant: IP and IN are used iff the value does not fit in IS.
Instances
| Bits Integer # | Since: base-2.1 |
Defined in GHC.Internal.Bits Methods (.&.) :: Integer -> Integer -> Integer # (.|.) :: Integer -> Integer -> Integer # xor :: Integer -> Integer -> Integer # complement :: Integer -> Integer # shift :: Integer -> Int -> Integer # rotate :: Integer -> Int -> Integer # setBit :: Integer -> Int -> Integer # clearBit :: Integer -> Int -> Integer # complementBit :: Integer -> Int -> Integer # testBit :: Integer -> Int -> Bool # bitSizeMaybe :: Integer -> Maybe Int # shiftL :: Integer -> Int -> Integer # unsafeShiftL :: Integer -> Int -> Integer # shiftR :: Integer -> Int -> Integer # unsafeShiftR :: Integer -> Int -> Integer # rotateL :: Integer -> Int -> Integer # | |
| Eq Integer # | |
| Ord Integer # | |
Defined in GHC.Internal.Bignum.Integer | |
| Data Integer # | 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) -> Integer -> c Integer # gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Integer # toConstr :: Integer -> Constr # dataTypeOf :: Integer -> DataType # dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Integer) # dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Integer) # gmapT :: (forall b. Data b => b -> b) -> Integer -> Integer # gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Integer -> r # gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Integer -> r # gmapQ :: (forall d. Data d => d -> u) -> Integer -> [u] # gmapQi :: Int -> (forall d. Data d => d -> u) -> Integer -> u # gmapM :: Monad m => (forall d. Data d => d -> m d) -> Integer -> m Integer # gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Integer -> m Integer # gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Integer -> m Integer # | |
| Enum Integer # | Since: base-2.1 |
| Ix Integer # | Since: base-2.1 |
Defined in GHC.Internal.Ix | |
| Num Integer # | Since: base-2.1 |
| Read Integer # | Since: base-2.1 |
| Integral Integer # | Since: base-2.0.1 |
Defined in GHC.Internal.Real | |
| Real Integer # | Since: base-2.0.1 |
Defined in GHC.Internal.Real Methods toRational :: Integer -> Rational # | |
| Show Integer # | Since: base-2.1 |
| Lift Integer # | |