ghc-bignum-1.0: GHC BigNum library

GHC.Num.BigNat

Description

Multi-precision natural

Synopsis

# Documentation

A BigNat

Represented as an array of limbs (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.

data BigNat Source #

A lifted BigNat

Represented as an array of limbs (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.

Constructors

 BN# FieldsunBigNat :: BigNat#

Check that the BigNat is valid

Check that the BigNat is valid

Number of words in the BigNat

Number of words in the BigNat

bigNatZero# :: (# #) -> BigNat# Source #

BigNat Zero

bigNatOne# :: (# #) -> BigNat# Source #

BigNat one

Indicate if a bigNat is zero

Indicate if a bigNat is zero

Indicate if a bigNat is one

Indicate if a bigNat is one

Indicate if a bigNat is two

Indicate if a bigNat is two

bigNatIsPowerOf2# :: BigNat# -> (# () | Word# #) Source #

Indicate if the value is a power of two and which one

Return the Word# at the given index

Return the Word# at the given index

Create a BigNat from a Word

Create a BigNat from a Word

Convert a list of non-zero Words (most-significant first) into a BigNat

Convert a list of non-zero Words (most-significant first) into a BigNat

Return the absolute value of the Int# in a BigNat

Convert a list of non-zero Words (most-significant first) into a BigNat. Don't remove most-significant zero words

Convert a BigNat into a list of non-zero Words (most-significant first)

Convert two Word# (most-significant first) into a BigNat

Convert a BigNat into a Word#

bigNatToWordMaybe# :: BigNat# -> (# Word# | () #) Source #

Convert a BigNat into a Word# if it fits

Convert a BigNat into a Word

Convert a BigNat into a Int#

Convert a BigNat into a Int

Encode ( exponent

Test if a BigNat is greater than a Word

Test if a BigNat is equal to a Word

Test if a BigNat is greater than a Word

Test if a BigNat is lower than or equal to a Word

Test if a BigNat is lower than or equal to a Word

Equality test for BigNat

Equality test for BigNat

Inequality test for BigNat

Equality test for BigNat

Compare a BigNat and a Word#

Compare a BigNat and a Word

Compare two BigNat

Predicate: a < b

Add a bigNat and a Word#

Add a bigNat and a Word

Multiply a BigNat by a Word#

Multiply a BigNAt by a Word

Square a BigNat

Multiplication (classical algorithm)

Subtract a Word# from a BigNat

The BigNat must be bigger than the Word#.

Subtract a Word# from a BigNat

The BigNat must be bigger than the Word#.

bigNatSubWord# :: BigNat# -> Word# -> (# () | BigNat# #) Source #

Subtract a Word# from a BigNat

Subtract two BigNat (don't check if a >= b)

bigNatSub :: BigNat# -> BigNat# -> (# () | BigNat# #) Source #

Subtract two BigNat

Divide a BigNat by a Word, return the quotient

Require: b /= 0

Divide a BigNat by a Word, return the quotient

Require: b /= 0

Divide a BigNat by a Word, return the remainder

Require: b /= 0

Divide a BigNat by a Word, return the remainder

Require: b /= 0

QuotRem a BigNat by a Word

Require: b /= 0

BigNat division returning (quotient,remainder)

BigNat division returning quotient

BigNat division returning remainder

Greatest common divisor between two Word#

Greatest common divisor between two Word

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

Greatest common divisor

Greatest common divisor

Least common multiple

Least common multiple with a Word#

Least common multiple between two Word#

Bitwise OR

Bitwise OR with Word#

Bitwise AND

Bitwise ANDNOT

Bitwise AND with Word#

Bitwise ANDNOT with Word#

Bitwise AND with Int#

Bitwise XOR

Bitwise XOR with Word#

PopCount for BigNat

PopCount for BigNat

Bit shift right

Bit shift right (two's complement)

Bit shift right

Bit shift left

Bit shift left

BigNat bit test

BigNat bit test

Return a BigNat whose bit i is the only one set.

Specialized version of bigNatShiftL (bigNatFromWord#)

Return a BigNat whose bit i is the only one set.

Specialized version of bigNatShiftL (bigNatFromWord#)

BigNat clear bit

BigNat set bit

Reverse the given bit

Base 2 logarithm

Base 2 logarithm

Logarithm for an arbitrary base

Logarithm for an arbitrary base

Logarithm for an arbitrary base

Logarithm for an arbitrary base

Compute the number of digits of the BigNat in the given base.

base must be > 1

Compute the number of digits of the BigNat in the given base.

base must be > 1

"bigNatPowModWord# b e m" computes base b raised to exponent e modulo m.

"bigNatPowMod b e m" computes base b raised to exponent e modulo m.

Return count of trailing zero bits

Return 0 for zero BigNat

Return count of trailing zero bits

Return 0 for zero BigNat

Return count of trailing zero words

Return 0 for zero BigNat

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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 0, the function will write and report zero bytes written.

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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 0, the function will write and report zero bytes written.

bigNatFromAddrLE# :: Word# -> Addr# -> State# s -> (# State# s, BigNat# #) Source #

The size is given in bytes.

Higher limbs equal to 0 are automatically trimed.

bigNatFromAddrBE# :: Word# -> Addr# -> State# s -> (# State# s, BigNat# #) Source #

The size is given in bytes.

Null higher limbs are automatically trimed.

bigNatFromAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, BigNat# #) Source #

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.

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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 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 "bigNatSizeInBase 256# i" to compute the exact number of bytes written in advance. In case of i == 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 trimed.

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 trimed.

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 trimed.