HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Moduleghc-bignum-1.3Haskell2010

GHC.Num.BigNat

Multi-precision natural

  • 2 types
  • 136 values
  • Packageghc-bignum-1.3
  • Exports138
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceBigNat.hs
typetype BigNat# = WordArray#
#

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.

datadata BigNat
#

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.

Constructors

Instances2Eq, Ord
  • Eq BigNatDefined in ghc-bignum-1.3 · GHC.Num.BigNat
  • Ord BigNatDefined in ghc-bignum-1.3 · GHC.Num.BigNat
valuebigNatRemWord# :: BigNat# -> Word# -> Word#
#

Divide a BigNat by a Word, return the remainder

Require: b /= 0

valuegcdWord# :: Word# -> Word# -> Word#
#

Greatest common divisor between two Word#

valuegcdInt# :: Int# -> Int# -> Int#
#

Greatest common divisor between two Int#

Warning: result may become negative if (at least) one argument is minBound

valuegcdInt :: Int -> Int -> Int
#

Greatest common divisor between two Int

Warning: result may become negative if (at least) one argument is minBound

valuebigNatBit# :: Word# -> BigNat#
#

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

Specialized version of `bigNatShiftL (bigNatFromWord# 1##)`

valuebigNatBit :: Word -> BigNat#
#

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

Specialized version of `bigNatShiftL (bigNatFromWord# 1##)`

valuebigNatSizeInBase# :: Word# -> BigNat# -> Word#
#

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

base must be > 1

valuebigNatCtz# :: BigNat# -> Word#
#

Return count of trailing zero bits

Return 0 for zero BigNat

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

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.

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

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.

valuebigNatToAddr#
  1. :: BigNat#
  2. -> Addr#
  3. -> Bool#
  4. -> State# s
  5. -> (# State# s, Word# #)
#

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.

valuebigNatToAddr :: BigNat# -> Addr# -> Bool# -> IO Word
#

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.

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

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.

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

Read a BigNat in base-256 big-endian representation from an Addr#.

The size is given in bytes.

Null higher limbs are automatically trimmed.

valuebigNatFromAddr#
  1. :: Word#
  2. -> Addr#
  3. -> Bool#
  4. -> State# s
  5. -> (# State# s, BigNat# #)
#

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.

valuebigNatToMutableByteArrayLE#
  1. :: BigNat#
  2. -> MutableByteArray# s
  3. -> Word#
  4. -> State# s
  5. -> (# State# s, Word# #)
#

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.

valuebigNatToMutableByteArrayBE#
  1. :: BigNat#
  2. -> MutableByteArray# s
  3. -> Word#
  4. -> State# s
  5. -> (# State# s, Word# #)
#

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.

valuebigNatToMutableByteArray#
  1. :: BigNat#
  2. -> MutableByteArray# s
  3. -> Word#
  4. -> Bool#
  5. -> State# s
  6. -> (# State# s, Word# #)
#

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.

valuebigNatFromByteArrayLE#
  1. :: Word#
  2. -> ByteArray#
  3. -> Word#
  4. -> State# s
  5. -> (# State# s, BigNat# #)
#

Read a BigNat in base-256 little-endian representation from a ByteArray#.

The size is given in bytes.

Null higher limbs are automatically trimmed.

valuebigNatFromByteArrayBE#
  1. :: Word#
  2. -> ByteArray#
  3. -> Word#
  4. -> State# s
  5. -> (# State# s, BigNat# #)
#

Read a BigNat in base-256 big-endian representation from a ByteArray#.

The size is given in bytes.

Null higher limbs are automatically trimmed.

valuebigNatFromByteArray#
  1. :: Word#
  2. -> ByteArray#
  3. -> Word#
  4. -> Bool#
  5. -> State# s
  6. -> (# State# s, BigNat# #)
#

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.