Compute absolute value of an Integer
Modulebase-4.22.0.0Haskell2010
GHC.Num.Integer
- 1 type
- 100 values
- Packagebase-4.22.0.0
- Exports101
- LanguageHaskell2010
- LicenceBSD-3-Clause
- SourceInteger.hs
Add two Integers
Bitwise AND operation
Fake 2's complement for negative values (might be slow)
Integer for which only n-th bit is set
Positive Integer for which only n-th bit is set
Check Integer invariants
Check Integer invariants
Compare two Integer
Binary complement of the
Decode a Double# into (# Integer mantissa, Int# exponent #)
Simultaneous integerDiv and integerMod.
Divisor must be non-zero otherwise the GHC runtime will terminate with a division-by-zero fault.
Simultaneous integerDiv and integerMod.
Divisor must be non-zero otherwise the GHC runtime will terminate with a division-by-zero fault.
Encode (Integer mantissa, Int exponent) into a Double
Encode (# Integer mantissa, Int# exponent #) into a Double#
Encode (# Integer mantissa, Int# exponent #) into a Float#
TODO: Not sure if it's worth to write Float optimized versions here
Equal predicate.
Equal predicate.
Read an Integer (without sign) in base-256 representation from an Addr#.
The size is given in bytes.
The endianness is selected with the Bool# parameter: most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Null higher limbs are automatically trimed.
Read an Integer (without sign) in base-256 representation from an Addr#.
The size is given in bytes.
The endianness is selected with the Bool# parameter: most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Null higher limbs are automatically trimed.
Create a positive Integer from a BigNat
Create a negative Integer from a BigNat
Create an Integer from a sign-bit and a BigNat
Read an Integer (without sign) in base-256 representation from a ByteArray#.
The size is given in bytes.
The endianness is selected with the Bool# parameter: most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Null higher limbs are automatically trimed.
Read an Integer (without sign) in base-256 representation from a ByteArray#.
The size is given in bytes.
The endianness is selected with the Bool# parameter: most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Null higher limbs are automatically trimed.
Create an Integer from an Int
Create an Integer from an Int#
Convert an Int64# into an Integer
Convert a Natural into an Integer
Convert a Word into an Integer
Convert a Word# into an Integer
Convert a Word64# into an Integer
Convert a list of Word into an Integer
Create a negative Integer with the given Word magnitude
Create an Integer from a sign and a Word magnitude
Compute greatest common divisor.
Get the extended GCD of two integers.
`integerGcde a b` returns (g,x,y) where * ax + by = g = |gcd a b|
Get the extended GCD of two integers.
`integerGcde# a b` returns (# g,x,y #) where * ax + by = g = |gcd a b|
Greater-or-equal predicate.
Greater-or-equal predicate.
Greater predicate.
Greater predicate.
Negative predicate
Negative predicate
One predicate
Indicate if the value is a power of two and which one
Zero predicate
Compute least common multiple.
Lower-or-equal predicate.
Lower-or-equal predicate.
Base 2 logarithm (floor)
For numbers <= 0, return 0
Base 2 logarithm (floor)
For numbers <= 0, return 0
Logarithm (floor) for an arbitrary base
For numbers <= 0, return 0
Logarithm (floor) for an arbitrary base
For numbers <= 0, return 0
Logarithm (floor) for an arbitrary base
For numbers <= 0, return 0
Logarithm (floor) for an arbitrary base
For numbers <= 0, return 0
Lower predicate.
Lower predicate.
Multiply two Integers
Not-equal predicate.
Not-equal predicate.
Negate Integer.
One edge-case issue to take into account is that Int's range is not
symmetric around 0. I.e. minBound+maxBound = -1
IP is used iff n > maxBound::Int IN is used iff n < minBound::Int
Integer One
Bitwise OR operation
Fake 2's complement for negative values (might be slow)
Count number of set bits. For negative arguments returns the negated population count of the absolute value.
Computes the modular exponentiation.
integerPowMod# b e m behaves as follows:
If m > 1 and e >= 0, it returns an integer y with 0 <= y < m and y congruent to b^e modulo m.
If m > 1 and e < 0, it uses integerRecipMod# to try to find a modular multiplicative inverse b' (which only exists if gcd b m = 1) and then caculates (b')^(-e) modulo m (note that -e > 0); if the inverse does not exist then it fails.
If m = 1, it returns
0for all b and e.If m = 0, it fails.
NB. Successful evaluation returns a value of the form (# n | #); failure is
indicated by returning (# | () #).
Simultaneous integerQuot and integerRem.
Divisor must be non-zero otherwise the GHC runtime will terminate with a division-by-zero fault.
Simultaneous integerQuot and integerRem.
Divisor must be non-zero otherwise the GHC runtime will terminate with a division-by-zero fault.
Computes the modular inverse.
integerRecipMod# x m behaves as follows:
If m > 1 and gcd x m = 1, it returns an integer y with 0 < y < m such that x*y is congruent to 1 modulo m.
If m > 1 and gcd x m > 1, it fails.
If m = 1, it returns
0for all x. The computation effectively takes place in the zero ring, which has a single element 0 with 0+0 = 0*0 = 0: the element 0 is the multiplicative identity element and is its own multiplicative inverse.If m = 0, it fails.
NB. Successful evaluation returns a value of the form (# n | #); failure is
indicated by returning (# | () #).
Shift-left operation
Remember that bits are stored in sign-magnitude form, hence the behavior of negative Integers is different from negative Int's behavior.
Shift-left operation
Shift-right operation
Fake 2's complement for negative values (might be slow)
Shift-right operation
Fake 2's complement for negative values (might be slow)
Return -1, 0, and 1 depending on whether argument is
negative, zero, or positive, respectively
Return -1#, 0#, and 1# depending on whether argument is
negative, zero, or positive, respectively
Compute the number of digits of the Integer (without the sign) in the given base.
base must be > 1
Square a Integer
Subtract one Integer from another.
Test if n-th bit is set. For negative Integers it tests the n-th bit of the negated argument.
Fake 2's complement for negative values (might be slow)
Test if n-th bit is set.
Fake 2's complement for negative values (might be slow)
Write an Integer (without sign) to addr in base-256 representation
and return the number of bytes written.
The endianness is selected with the Bool# parameter: write most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Write an Integer (without sign) to addr in base-256 representation
and return the number of bytes written.
The endianness is selected with the Bool# parameter: write most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Convert an Integer into a BigNat.
Return 0 for negative Integers.
Convert an Integer into a sign-bit and a BigNat
Convert an Integer into an Int64#
Write an Integer (without sign) in base-256 representation and return the number of bytes written.
The endianness is selected with the Bool# parameter: most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Write an Integer (without sign) in base-256 representation and return the number of bytes written.
The endianness is selected with the Bool# parameter: most significant
byte first (big-endian) if 1# or least significant byte first
(little-endian) if 0#.
Convert an Integer into a Natural
Return absolute value
Convert an Integer into a Natural
Return 0 for negative Integers.
Convert an Integer into a Natural
Throw an Underflow exception if input is negative.
Truncate an Integer into a Word
Truncate an Integer into a Word
Convert an Integer into a Word64#
Bitwise XOR operation
Fake 2's complement for negative values (might be slow)
Integer Zero
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.
Constructors
IS Int#IP ByteArray#iff value in
]maxBound::Int, +inf[rangeIN ByteArray#iff value in
]-inf, minBound::Int[range
Instances13Enum, Eq, Integral, Data, Num, Ord, …
Enum IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.EnumEq IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.Bignum.IntegerIntegral IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.RealData IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.Data.DataNum IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.NumOrd IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.Bignum.IntegerRead IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.ReadReal IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.RealShow IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.ShowIx IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.IxBits IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.BitsPrintfArg IntegerDefined in base-4.22.0.0 · Text.PrintfLift IntegerDefined in ghc-internal-9.1401.0 · GHC.Internal.TH.Lift