ghc-bignum-1.0: GHC BigNum library
Safe HaskellSafe-Inferred
LanguageHaskell2010

GHC.Num.Natural

Synopsis

Documentation

data Natural Source #

Natural number

Invariant: numbers <= 0xffffffffffffffff use the NS constructor

Constructors

NS !Word# 
NB !BigNat# 

Instances

Instances details
Eq Natural # 
Instance details

Defined in GHC.Num.Natural

Ord Natural # 
Instance details

Defined in GHC.Num.Natural

naturalCheck# :: Natural -> Bool# Source #

Check Natural invariants

naturalCheck :: Natural -> Bool Source #

Check Natural invariants

naturalZero :: Natural Source #

Zero Natural

naturalOne :: Natural Source #

One Natural

naturalIsZero :: Natural -> Bool Source #

Test Zero Natural

naturalIsOne :: Natural -> Bool Source #

Test One Natural

naturalIsPowerOf2# :: Natural -> (# (# #) | Word# #) Source #

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

naturalFromBigNat# :: BigNat# -> Natural Source #

Create a Natural from a BigNat# (respect the invariants)

naturalToBigNat# :: Natural -> BigNat# Source #

Convert a Natural into a BigNat#

naturalFromWord# :: Word# -> Natural Source #

Create a Natural from a Word#

naturalFromWord2# :: Word# -> Word# -> Natural Source #

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

naturalFromWord :: Word -> Natural Source #

Create a Natural from a Word

naturalFromWordList :: [Word] -> Natural Source #

Create a Natural from a list of Word

naturalToWord# :: Natural -> Word# Source #

Convert the lower bits of a Natural into a Word#

naturalToWord :: Natural -> Word Source #

Convert the lower bits of a Natural into a Word

naturalToWordClamp# :: Natural -> Word# Source #

Convert a Natural into a Word# clamping to (maxBound :: Word#).

naturalToWordClamp :: Natural -> Word Source #

Convert a Natural into a Word# clamping to (maxBound :: Word).

naturalToWordMaybe# :: Natural -> (# (# #) | Word# #) Source #

Try downcasting Natural to Word value. Returns (##) if value doesn't fit in Word.

naturalEncodeDouble# :: Natural -> Int# -> Double# Source #

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

naturalToDouble# :: Natural -> Double# Source #

Encode a Natural (mantissa) into a Double#

naturalToFloat# :: Natural -> Float# Source #

Encode a Natural (mantissa) into a Float#

naturalEncodeFloat# :: Natural -> Int# -> Float# Source #

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

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

naturalEq# :: Natural -> Natural -> Bool# Source #

Equality test for Natural

naturalEq :: Natural -> Natural -> Bool Source #

Equality test for Natural

naturalNe# :: Natural -> Natural -> Bool# Source #

Inequality test for Natural

naturalNe :: Natural -> Natural -> Bool Source #

Inequality test for Natural

naturalGe# :: Natural -> Natural -> Bool# Source #

Greater or equal test for Natural

naturalGe :: Natural -> Natural -> Bool Source #

Greater or equal test for Natural

naturalLe# :: Natural -> Natural -> Bool# Source #

Lower or equal test for Natural

naturalLe :: Natural -> Natural -> Bool Source #

Lower or equal test for Natural

naturalGt# :: Natural -> Natural -> Bool# Source #

Greater test for Natural

naturalGt :: Natural -> Natural -> Bool Source #

Greater test for Natural

naturalLt# :: Natural -> Natural -> Bool# Source #

Lower test for Natural

naturalLt :: Natural -> Natural -> Bool Source #

Lower test for Natural

naturalCompare :: Natural -> Natural -> Ordering Source #

Compare two Natural

naturalPopCount# :: Natural -> Word# Source #

PopCount for Natural

naturalPopCount :: Natural -> Word Source #

PopCount for Natural

naturalShiftR# :: Natural -> Word# -> Natural Source #

Right shift for Natural

naturalShiftR :: Natural -> Word -> Natural Source #

Right shift for Natural

naturalAdd :: Natural -> Natural -> Natural Source #

Add two naturals

naturalSub :: Natural -> Natural -> (# (# #) | Natural #) Source #

Sub two naturals

naturalSubThrow :: Natural -> Natural -> Natural Source #

Sub two naturals

Throw an Underflow exception if x < y

naturalSubUnsafe :: Natural -> Natural -> Natural Source #

Sub two naturals

Unsafe: don't check that x >= y Undefined results if it happens

naturalMul :: Natural -> Natural -> Natural Source #

Multiplication

naturalSqr :: Natural -> Natural Source #

Square a Natural

naturalSignum :: Natural -> Natural Source #

Signum for Natural

naturalNegate :: Natural -> Natural Source #

Negate for Natural

naturalQuotRem# :: Natural -> Natural -> (# Natural, Natural #) Source #

Return division quotient and remainder

Division by zero is handled by BigNat

naturalQuotRem :: Natural -> Natural -> (Natural, Natural) Source #

Return division quotient and remainder

naturalQuot :: Natural -> Natural -> Natural Source #

Return division quotient

naturalRem :: Natural -> Natural -> Natural Source #

Return division remainder

naturalGcd :: Natural -> Natural -> Natural Source #

Compute greatest common divisor.

naturalLcm :: Natural -> Natural -> Natural Source #

Compute least common multiple.

naturalLog2# :: Natural -> Word# Source #

Base 2 logarithm

naturalLog2 :: Natural -> Word Source #

Base 2 logarithm

naturalLogBaseWord# :: Word# -> Natural -> Word# Source #

Logarithm for an arbitrary base

naturalLogBaseWord :: Word -> Natural -> Word Source #

Logarithm for an arbitrary base

naturalLogBase# :: Natural -> Natural -> Word# Source #

Logarithm for an arbitrary base

naturalLogBase :: Natural -> Natural -> Word Source #

Logarithm for an arbitrary base

naturalPowMod :: Natural -> Natural -> Natural -> Natural Source #

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

naturalSizeInBase# :: Word# -> Natural -> Word# Source #

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

base must be > 1

naturalToAddr# :: Natural -> Addr# -> Bool# -> State# s -> (# State# s, Word# #) Source #

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

naturalToAddr :: Natural -> Addr# -> Bool# -> IO Word Source #

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

naturalFromAddr# :: Word# -> Addr# -> Bool# -> State# s -> (# State# s, Natural #) Source #

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.

naturalFromAddr :: Word# -> Addr# -> Bool# -> IO Natural Source #

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.

naturalToMutableByteArray# :: Natural -> MutableByteArray# s -> Word# -> Bool# -> State# s -> (# State# s, Word# #) Source #

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

naturalFromByteArray# :: Word# -> ByteArray# -> Word# -> Bool# -> State# s -> (# State# s, Natural #) Source #

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.