Integer package:ihaskell
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 (fit into an
Int),
IS constructor
is used. Otherwise
Integer and
IN constructors are used
to store a
BigNat representing respectively the positive or the
negative value magnitude.
Invariant:
Integer and
IN are used iff value doesn't fit
in
IS
Compute absolute value of an
Integer
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
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
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.