Safe Haskell | Safe-Inferred |
---|---|
Language | Haskell2010 |
Multi-precision natural
Synopsis
- type BigNat# = WordArray#
- data BigNat = BN# {}
- bigNatCheck# :: BigNat# -> Bool#
- bigNatCheck :: BigNat# -> Bool
- bigNatSize :: BigNat# -> Word
- bigNatSize# :: BigNat# -> Int#
- bigNatZero :: BigNat
- bigNatOne :: BigNat
- bigNatZero# :: (# #) -> BigNat#
- bigNatOne# :: (# #) -> BigNat#
- raiseDivZero_BigNat :: (# #) -> BigNat#
- bigNatIsZero :: BigNat# -> Bool
- bigNatIsZero# :: BigNat# -> Bool#
- bigNatIsOne :: BigNat# -> Bool
- bigNatIsOne# :: BigNat# -> Bool#
- bigNatIsTwo :: BigNat# -> Bool
- bigNatIsTwo# :: BigNat# -> Bool#
- bigNatIsPowerOf2# :: BigNat# -> (# (# #) | Word# #)
- bigNatIndex# :: BigNat# -> Int# -> Word#
- bigNatIndex :: BigNat# -> Int# -> Word
- bigNatFromWord :: Word -> BigNat#
- bigNatFromWord# :: Word# -> BigNat#
- bigNatFromWordList :: [Word] -> BigNat#
- bigNatFromWordList# :: [Word] -> WordArray#
- bigNatFromAbsInt# :: Int# -> BigNat#
- bigNatFromWordListUnsafe :: [Word] -> BigNat#
- bigNatToWordList :: BigNat# -> [Word]
- bigNatFromWord2# :: Word# -> Word# -> BigNat#
- bigNatToWord# :: BigNat# -> Word#
- bigNatToWordMaybe# :: BigNat# -> (# (# #) | Word# #)
- bigNatToWord :: BigNat# -> Word
- bigNatToInt# :: BigNat# -> Int#
- bigNatToInt :: BigNat# -> Int
- bigNatFromWord64# :: Word64# -> BigNat#
- bigNatToWord64# :: BigNat# -> Word64#
- bigNatEncodeDouble# :: BigNat# -> Int# -> Double#
- bigNatGtWord# :: BigNat# -> Word# -> Bool#
- bigNatEqWord# :: BigNat# -> Word# -> Bool#
- bigNatGtWord :: BigNat# -> Word -> Bool
- bigNatLeWord# :: BigNat# -> Word# -> Bool#
- bigNatLeWord :: BigNat# -> Word -> Bool
- bigNatEq# :: BigNat# -> BigNat# -> Bool#
- bigNatEq :: BigNat# -> BigNat# -> Bool
- bigNatNe# :: BigNat# -> BigNat# -> Bool#
- bigNatNe :: BigNat# -> BigNat# -> Bool
- bigNatCompareWord# :: BigNat# -> Word# -> Ordering
- bigNatCompareWord :: BigNat# -> Word -> Ordering
- bigNatCompare :: BigNat# -> BigNat# -> Ordering
- bigNatLt# :: BigNat# -> BigNat# -> Bool#
- bigNatLt :: BigNat# -> BigNat# -> Bool
- bigNatLe# :: BigNat# -> BigNat# -> Bool#
- bigNatLe :: BigNat# -> BigNat# -> Bool
- bigNatGt# :: BigNat# -> BigNat# -> Bool#
- bigNatGt :: BigNat# -> BigNat# -> Bool
- bigNatGe# :: BigNat# -> BigNat# -> Bool#
- bigNatGe :: BigNat# -> BigNat# -> Bool
- bigNatAddWord# :: BigNat# -> Word# -> BigNat#
- bigNatAddWord :: BigNat# -> Word -> BigNat#
- bigNatAdd :: BigNat# -> BigNat# -> BigNat#
- bigNatMulWord# :: BigNat# -> Word# -> BigNat#
- bigNatMulWord :: BigNat# -> Word -> BigNat#
- bigNatSqr :: BigNat# -> BigNat#
- bigNatMul :: BigNat# -> BigNat# -> BigNat#
- bigNatSubWordUnsafe# :: BigNat# -> Word# -> BigNat#
- bigNatSubWordUnsafe :: BigNat# -> Word -> BigNat#
- bigNatSubWord# :: BigNat# -> Word# -> (# (# #) | BigNat# #)
- bigNatSubUnsafe :: BigNat# -> BigNat# -> BigNat#
- bigNatSub :: BigNat# -> BigNat# -> (# (# #) | BigNat# #)
- bigNatQuotWord# :: BigNat# -> Word# -> BigNat#
- bigNatQuotWord :: BigNat# -> Word -> BigNat#
- bigNatRemWord# :: BigNat# -> Word# -> Word#
- bigNatRemWord :: BigNat# -> Word -> Word
- bigNatQuotRemWord# :: BigNat# -> Word# -> (# BigNat#, Word# #)
- bigNatQuotRem# :: BigNat# -> BigNat# -> (# BigNat#, BigNat# #)
- bigNatQuot :: BigNat# -> BigNat# -> BigNat#
- bigNatRem :: BigNat# -> BigNat# -> BigNat#
- gcdWord# :: Word# -> Word# -> Word#
- gcdWord :: Word -> Word -> Word
- gcdInt# :: Int# -> Int# -> Int#
- gcdInt :: Int -> Int -> Int
- bigNatGcd :: BigNat# -> BigNat# -> BigNat#
- bigNatGcdWord# :: BigNat# -> Word# -> Word#
- bigNatLcm :: BigNat# -> BigNat# -> BigNat#
- bigNatLcmWord# :: BigNat# -> Word# -> BigNat#
- bigNatLcmWordWord# :: Word# -> Word# -> BigNat#
- bigNatOr :: BigNat# -> BigNat# -> BigNat#
- bigNatOrWord# :: BigNat# -> Word# -> BigNat#
- bigNatAnd :: BigNat# -> BigNat# -> BigNat#
- bigNatAndNot :: BigNat# -> BigNat# -> BigNat#
- bigNatAndWord# :: BigNat# -> Word# -> BigNat#
- bigNatAndNotWord# :: BigNat# -> Word# -> BigNat#
- bigNatAndInt# :: BigNat# -> Int# -> BigNat#
- bigNatXor :: BigNat# -> BigNat# -> BigNat#
- bigNatXorWord# :: BigNat# -> Word# -> BigNat#
- bigNatPopCount :: BigNat# -> Word
- bigNatPopCount# :: BigNat# -> Word#
- bigNatShiftR# :: BigNat# -> Word# -> BigNat#
- bigNatShiftRNeg# :: BigNat# -> Word# -> BigNat#
- bigNatShiftR :: BigNat# -> Word -> BigNat#
- bigNatShiftL :: BigNat# -> Word -> BigNat#
- bigNatShiftL# :: BigNat# -> Word# -> BigNat#
- bigNatTestBit# :: BigNat# -> Word# -> Bool#
- bigNatTestBit :: BigNat# -> Word -> Bool
- bigNatBit# :: Word# -> BigNat#
- bigNatBit :: Word -> BigNat#
- bigNatClearBit# :: BigNat# -> Word# -> BigNat#
- bigNatSetBit# :: BigNat# -> Word# -> BigNat#
- bigNatComplementBit# :: BigNat# -> Word# -> BigNat#
- bigNatLog2# :: BigNat# -> Word#
- bigNatLog2 :: BigNat# -> Word
- bigNatLogBase# :: BigNat# -> BigNat# -> Word#
- bigNatLogBase :: BigNat# -> BigNat# -> Word
- bigNatLogBaseWord# :: Word# -> BigNat# -> Word#
- bigNatLogBaseWord :: Word -> BigNat# -> Word
- bigNatSizeInBase# :: Word# -> BigNat# -> Word#
- bigNatSizeInBase :: Word -> BigNat# -> Word
- powModWord# :: Word# -> Word# -> Word# -> Word#
- bigNatPowModWord# :: BigNat# -> BigNat# -> Word# -> Word#
- bigNatPowMod :: BigNat# -> BigNat# -> BigNat# -> BigNat#
- bigNatCtz# :: BigNat# -> Word#
- bigNatCtz :: BigNat# -> Word
- bigNatCtzWord# :: BigNat# -> Word#
- bigNatCtzWord :: BigNat# -> Word
- bigNatToAddrLE# :: BigNat# -> Addr# -> State# s -> (# State# s, Word# #)
- bigNatToAddrBE# :: BigNat# -> Addr# -> State# s -> (# State# s, Word# #)
- bigNatToAddr# :: BigNat# -> Addr# -> Bool# -> State# s -> (# State# s, Word# #)
- bigNatToAddr :: BigNat# -> Addr# -> Bool# -> IO Word
- bigNatFromAddrLE# :: Word# -> Addr# -> State# s -> (# State# s, BigNat# #)
- bigNatFromAddrBE# :: Word# -> Addr# -> State# s -> (# State# s, BigNat# #)
- bigNatFromAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, BigNat# #)
- bigNatToMutableByteArrayLE# :: BigNat# -> MutableByteArray# s -> Word# -> State# s -> (# State# s, Word# #)
- bigNatToMutableByteArrayBE# :: BigNat# -> MutableByteArray# s -> Word# -> State# s -> (# State# s, Word# #)
- bigNatToMutableByteArray# :: BigNat# -> MutableByteArray# s -> Word# -> Bool# -> State# s -> (# State# s, Word# #)
- bigNatFromByteArrayLE# :: Word# -> ByteArray# -> Word# -> State# s -> (# State# s, BigNat# #)
- bigNatFromByteArrayBE# :: Word# -> ByteArray# -> Word# -> State# s -> (# State# s, BigNat# #)
- bigNatFromByteArray# :: Word# -> ByteArray# -> Word# -> Bool# -> State# s -> (# State# s, BigNat# #)
- bigNatFromWordArray# :: WordArray# -> Word# -> BigNat#
- bigNatFromWordArray :: WordArray# -> Word# -> BigNat
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.
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)