GHC.Num.Natural
Documentation
Natural number
Invariant: numbers <= 0xffffffffffffffff use the NS
constructor
Instances
Eq Natural Source # | |
Ord Natural Source # | |
naturalCheck# :: Natural -> Bool# Source #
Check Natural invariants
naturalCheck :: Natural -> Bool Source #
Check Natural invariants
naturalZero :: Natural Source #
Zero Natural
naturalOne :: Natural Source #
One Natural
naturalIsZero :: Natural -> Bool Source #
Test Zero Natural
naturalIsOne :: Natural -> Bool Source #
Test One Natural
naturalIsPowerOf2# :: Natural -> (# (# #) | Word# #) Source #
Indicate if the value is a power of two and which one
naturalFromBigNat# :: BigNat# -> Natural Source #
Create a Natural from a BigNat# (respect the invariants)
naturalToBigNat# :: Natural -> BigNat# Source #
Convert a Natural into a BigNat#
naturalFromWord# :: Word# -> Natural Source #
Create a Natural from a Word#
naturalFromWord2# :: Word# -> Word# -> Natural Source #
Convert two Word# (most-significant first) into a Natural
naturalFromWord :: Word -> Natural Source #
Create a Natural from a Word
naturalFromWordList :: [Word] -> Natural Source #
Create a Natural from a list of Word
naturalToWord# :: Natural -> Word# Source #
Convert the lower bits of a Natural into a Word#
naturalToWord :: Natural -> Word Source #
Convert the lower bits of a Natural into a Word
naturalToWordClamp# :: Natural -> Word# Source #
Convert a Natural into a Word# clamping to (maxBound :: Word#).
naturalToWordClamp :: Natural -> Word Source #
Convert a Natural into a Word# clamping to (maxBound :: Word).
naturalToWordMaybe# :: Natural -> (# (# #) | Word# #) Source #
naturalEncodeDouble# :: Natural -> Int# -> Double# Source #
Encode (# Natural mantissa, Int# exponent #) into a Double#
naturalEncodeFloat# :: Natural -> Int# -> Float# Source #
Encode (# Natural mantissa, Int# exponent #) into a Float#
TODO: Not sure if it's worth to write Float
optimized versions here
naturalPopCount# :: Natural -> Word# Source #
PopCount for Natural
naturalPopCount :: Natural -> Word Source #
PopCount for Natural
naturalSubThrow :: Natural -> Natural -> Natural Source #
Sub two naturals
Throw an Underflow exception if x < y
naturalSubUnsafe :: Natural -> Natural -> Natural Source #
Sub two naturals
Unsafe: don't check that x >= y Undefined results if it happens
naturalSqr :: Natural -> Natural Source #
Square a Natural
naturalSignum :: Natural -> Natural Source #
Signum for Natural
naturalNegate :: Natural -> Natural Source #
Negate for Natural
naturalQuotRem# :: Natural -> Natural -> (# Natural, Natural #) Source #
Return division quotient and remainder
Division by zero is handled by BigNat
naturalQuotRem :: Natural -> Natural -> (Natural, Natural) Source #
Return division quotient and remainder
naturalBit# :: Word# -> Natural Source #
naturalBit :: Word -> Natural Source #
naturalLog2# :: Natural -> Word# Source #
Base 2 logarithm
naturalLog2 :: Natural -> Word Source #
Base 2 logarithm
naturalPowMod :: Natural -> Natural -> Natural -> Natural Source #
"
" computes base naturalPowMod
b e mb
raised to
exponent e
modulo m
.
naturalSizeInBase# :: Word# -> Natural -> Word# Source #
Compute the number of digits of the Natural in the given base.
base
must be > 1
naturalToAddr# :: Natural -> Addr# -> Bool# -> State# s -> (# State# s, Word# #) Source #
Write a Natural
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#
.
naturalToAddr :: Natural -> Addr# -> Bool# -> IO Word Source #
Write a Natural
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#
.
naturalFromAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, Natural #) Source #
Read a Natural 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.
naturalFromAddr :: Word# -> Addr# -> Bool# -> IO Natural Source #
Read a Natural 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.
naturalToMutableByteArray# :: Natural -> MutableByteArray# s -> Word# -> Bool# -> State# s -> (# State# s, Word# #) Source #
Write a Natural 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#
.
naturalFromByteArray# :: Word# -> ByteArray# -> Word# -> Bool# -> State# s -> (# State# s, Natural #) Source #
Read a Natural 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.