GHC.Num.BigNat
Multi-precision natural
Documentation
type BigNat# = WordArray# Source #
A BigNat
Represented as an array of limbs (Word#) stored in little-endian order (Word# themselves use machine order).
Invariant (canonical representation): higher Word# is non-zero.
As a consequence, zero is represented with a WordArray# whose size is 0.
A lifted BigNat
Represented as an array of limbs (Word#) stored in little-endian order (Word# themselves use machine order).
Invariant (canonical representation): higher Word# is non-zero.
As a consequence, zero is represented with a WordArray# whose size is 0.
Instances
Eq BigNat Source # | |
Ord BigNat Source # | |
bigNatCheck# :: BigNat# -> Bool# Source #
Check that the BigNat is valid
bigNatCheck :: BigNat# -> Bool Source #
Check that the BigNat is valid
bigNatSize :: BigNat# -> Word Source #
Number of words in the BigNat
bigNatSize# :: BigNat# -> Int# Source #
Number of words in the BigNat
bigNatZero :: BigNat Source #
bigNatZero# :: (# #) -> BigNat# Source #
BigNat Zero
bigNatOne# :: (# #) -> BigNat# Source #
BigNat one
raiseDivZero_BigNat :: (# #) -> BigNat# Source #
bigNatIsZero :: BigNat# -> Bool Source #
Indicate if a bigNat is zero
bigNatIsZero# :: BigNat# -> Bool# Source #
Indicate if a bigNat is zero
bigNatIsOne :: BigNat# -> Bool Source #
Indicate if a bigNat is one
bigNatIsOne# :: BigNat# -> Bool# Source #
Indicate if a bigNat is one
bigNatIsTwo :: BigNat# -> Bool Source #
Indicate if a bigNat is two
bigNatIsTwo# :: BigNat# -> Bool# Source #
Indicate if a bigNat is two
bigNatIsPowerOf2# :: BigNat# -> (# (# #) | Word# #) Source #
Indicate if the value is a power of two and which one
bigNatFromWord :: Word -> BigNat# Source #
Create a BigNat from a Word
bigNatFromWord# :: Word# -> BigNat# Source #
Create a BigNat from a Word
bigNatFromWordList :: [Word] -> BigNat# Source #
Convert a list of non-zero Words (most-significant first) into a BigNat
bigNatFromWordList# :: [Word] -> WordArray# Source #
Convert a list of non-zero Words (most-significant first) into a BigNat
bigNatFromAbsInt# :: Int# -> BigNat# Source #
Return the absolute value of the Int# in a BigNat
bigNatFromWordListUnsafe :: [Word] -> BigNat# Source #
Convert a list of non-zero Words (most-significant first) into a BigNat. Don't remove most-significant zero words
bigNatToWordList :: BigNat# -> [Word] Source #
Convert a BigNat into a list of non-zero Words (most-significant first)
bigNatFromWord2# :: Word# -> Word# -> BigNat# Source #
Convert two Word# (most-significant first) into a BigNat
bigNatToWord# :: BigNat# -> Word# Source #
Convert a BigNat into a Word#
bigNatToWordMaybe# :: BigNat# -> (# (# #) | Word# #) Source #
Convert a BigNat into a Word# if it fits
bigNatToWord :: BigNat# -> Word Source #
Convert a BigNat into a Word
bigNatToInt# :: BigNat# -> Int# Source #
Convert a BigNat into a Int#
bigNatToInt :: BigNat# -> Int Source #
Convert a BigNat into a Int
bigNatFromWord64# :: Word64# -> BigNat# Source #
Convert a Word64# into a BigNat on 64-bit architectures
bigNatToWord64# :: BigNat# -> Word64# Source #
Convert a BigNat into a Word64# on 64-bit architectures
bigNatEncodeDouble# :: BigNat# -> Int# -> Double# Source #
Encode (# BigNat mantissa, Int# exponent #) into a Double#
bigNatLeWord# :: BigNat# -> Word# -> Bool# Source #
Test if a BigNat is lower than or equal to a Word
bigNatSubWordUnsafe# :: BigNat# -> Word# -> BigNat# Source #
Subtract a Word# from a BigNat
The BigNat must be bigger than the Word#.
bigNatSubWordUnsafe :: BigNat# -> Word -> BigNat# Source #
Subtract a Word# from a BigNat
The BigNat must be bigger than the Word#.
bigNatSubUnsafe :: BigNat# -> BigNat# -> BigNat# Source #
Subtract two BigNat (don't check if a >= b)
bigNatQuotWord# :: BigNat# -> Word# -> BigNat# Source #
Divide a BigNat by a Word, return the quotient
Require: b /= 0
bigNatQuotWord :: BigNat# -> Word -> BigNat# Source #
Divide a BigNat by a Word, return the quotient
Require: b /= 0
bigNatRemWord# :: BigNat# -> Word# -> Word# Source #
Divide a BigNat by a Word, return the remainder
Require: b /= 0
bigNatRemWord :: BigNat# -> Word -> Word Source #
Divide a BigNat by a Word, return the remainder
Require: b /= 0
bigNatQuotRemWord# :: BigNat# -> Word# -> (# BigNat#, Word# #) Source #
QuotRem a BigNat by a Word
Require: b /= 0
bigNatQuotRem# :: BigNat# -> BigNat# -> (# BigNat#, BigNat# #) Source #
BigNat division returning (quotient,remainder)
gcdInt# :: Int# -> Int# -> Int# Source #
Greatest common divisor between two Int#
Warning: result may become negative if (at least) one argument
is minBound
gcdInt :: Int -> Int -> Int Source #
Greatest common divisor between two Int
Warning: result may become negative if (at least) one argument
is minBound
bigNatPopCount :: BigNat# -> Word Source #
PopCount for BigNat
bigNatPopCount# :: BigNat# -> Word# Source #
PopCount for BigNat
bigNatBit# :: Word# -> BigNat# Source #
Return a BigNat whose bit i
is the only one set.
Specialized version of `bigNatShiftL (bigNatFromWord# 1##)`
bigNatBit :: Word -> BigNat# Source #
Return a BigNat whose bit i
is the only one set.
Specialized version of `bigNatShiftL (bigNatFromWord# 1##)`
bigNatLog2# :: BigNat# -> Word# Source #
Base 2 logarithm
bigNatLog2 :: BigNat# -> Word Source #
Base 2 logarithm
bigNatSizeInBase# :: Word# -> BigNat# -> Word# Source #
Compute the number of digits of the BigNat in the given base.
base
must be > 1
bigNatSizeInBase :: Word -> BigNat# -> Word Source #
Compute the number of digits of the BigNat in the given base.
base
must be > 1
bigNatPowModWord# :: BigNat# -> BigNat# -> Word# -> Word# Source #
"
" computes base bigNatPowModWord#
b e mb
raised to
exponent e
modulo m
.
bigNatPowMod :: BigNat# -> BigNat# -> BigNat# -> BigNat# Source #
"
" computes base bigNatPowMod
b e mb
raised to
exponent e
modulo m
.
bigNatCtz# :: BigNat# -> Word# Source #
Return count of trailing zero bits
Return 0 for zero BigNat
bigNatCtzWord# :: BigNat# -> Word# Source #
Return count of trailing zero words
Return 0 for zero BigNat
bigNatCtzWord :: BigNat# -> Word Source #
Return count of trailing zero words
Return 0 for zero BigNat
bigNatToAddrLE# :: BigNat# -> Addr# -> State# s -> (# State# s, Word# #) Source #
Write a BigNat in base-256 little-endian representation and return the number of bytes written.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatToAddrBE# :: BigNat# -> Addr# -> State# s -> (# State# s, Word# #) Source #
Write a BigNat in base-256 big-endian representation and return the number of bytes written.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatToAddr# :: BigNat# -> Addr# -> Bool# -> State# s -> (# State# s, Word# #) Source #
Write a BigNat 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#
.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatToAddr :: BigNat# -> Addr# -> Bool# -> IO Word Source #
Write a BigNat 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#
.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatFromAddrLE# :: Word# -> Addr# -> State# s -> (# State# s, BigNat# #) Source #
Read a BigNat in base-256 little-endian representation from an Addr#.
The size is given in bytes.
Higher limbs equal to 0 are automatically trimmed.
bigNatFromAddrBE# :: Word# -> Addr# -> State# s -> (# State# s, BigNat# #) Source #
Read a BigNat in base-256 big-endian representation from an Addr#.
The size is given in bytes.
Null higher limbs are automatically trimmed.
bigNatFromAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, BigNat# #) Source #
Read a BigNat 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 trimmed.
bigNatToMutableByteArrayLE# :: BigNat# -> MutableByteArray# s -> Word# -> State# s -> (# State# s, Word# #) Source #
Write a BigNat in base-256 little-endian representation and return the number of bytes written.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatToMutableByteArrayBE# :: BigNat# -> MutableByteArray# s -> Word# -> State# s -> (# State# s, Word# #) Source #
Write a BigNat in base-256 big-endian representation and return the number of bytes written.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatToMutableByteArray# :: BigNat# -> MutableByteArray# s -> Word# -> Bool# -> State# s -> (# State# s, Word# #) Source #
Write a BigNat 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#
.
Use "
" to compute the exact number of bytes
written in advance. In case of bigNatSizeInBase
256# ii == 0
, the function will write and report
zero bytes written.
bigNatFromByteArrayLE# :: Word# -> ByteArray# -> Word# -> State# s -> (# State# s, BigNat# #) Source #
Read a BigNat in base-256 little-endian representation from a ByteArray#.
The size is given in bytes.
Null higher limbs are automatically trimmed.
bigNatFromByteArrayBE# :: Word# -> ByteArray# -> Word# -> State# s -> (# State# s, BigNat# #) Source #
Read a BigNat in base-256 big-endian representation from a ByteArray#.
The size is given in bytes.
Null higher limbs are automatically trimmed.
bigNatFromByteArray# :: Word# -> ByteArray# -> Word# -> Bool# -> State# s -> (# State# s, BigNat# #) Source #
Read a BigNat 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 trimmed.
bigNatFromWordArray# :: WordArray# -> Word# -> BigNat# Source #
Create a BigNat# from a WordArray# containing n limbs in least-significant-first order.
If possible WordArray#
, will be used directly (i.e. shared
without cloning the WordArray#
into a newly allocated one)
bigNatFromWordArray :: WordArray# -> Word# -> BigNat Source #
Create a BigNat from a WordArray# containing n limbs in least-significant-first order.
If possible WordArray#
, will be used directly (i.e. shared
without cloning the WordArray#
into a newly allocated one)