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

  • Packageghc-bignum-1.3
  • Exports82
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceNatural.hs
datadata Natural
#

Natural number

Invariant: numbers <= 0xffffffffffffffff use the NS constructor

Constructors

  • NS Word#
  • NB ByteArray#
Instances2Eq, Ord
  • Eq NaturalDefined in ghc-bignum-1.3 · GHC.Num.Natural
  • Ord NaturalDefined in ghc-bignum-1.3 · GHC.Num.Natural

Useful constants

2 declarations

Predicates

3 declarations

Conversion with...

0 declarations

BigNat

Word

Limbs

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

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

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

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.

Floating point

valuenaturalEncodeFloat# :: Natural -> Int# -> Float#
#

Encode (# Natural mantissa, Int# exponent #) into a Float#

TODO: Not sure if it's worth to write Float optimized versions here

Addr#

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

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

valuenaturalToAddr :: Natural -> Addr# -> Bool# -> IO Word
#

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

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

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.

valuenaturalFromAddr :: Word# -> Addr# -> Bool# -> IO Natural
#

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.

Comparison

13 declarations

Bit operations

20 declarations

Arithmetic

21 declarations

Miscellaneous

1 declaration
valuenaturalSizeInBase# :: Word# -> Natural -> Word#
#

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

base must be > 1