ghc-internal-9.1300.0: Basic libraries
Safe HaskellNone
LanguageHaskell2010

GHC.Internal.Bignum.Natural

Synopsis

Documentation

data Natural Source #

Natural number

Invariant: numbers <= 0xffffffffffffffff use the NS constructor

Constructors

NS Word# 
NB ByteArray# 

Instances

Instances details
Bits Natural Source #

Since: base-4.8.0

Instance details

Defined in GHC.Internal.Bits

Data Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Data.Data

Methods

gfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Natural -> c Natural Source #

gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Natural Source #

toConstr :: Natural -> Constr Source #

dataTypeOf :: Natural -> DataType Source #

dataCast1 :: Typeable t => (forall d. Data d => c (t d)) -> Maybe (c Natural) Source #

dataCast2 :: Typeable t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Natural) Source #

gmapT :: (forall b. Data b => b -> b) -> Natural -> Natural Source #

gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r Source #

gmapQr :: forall r r'. (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Natural -> r Source #

gmapQ :: (forall d. Data d => d -> u) -> Natural -> [u] Source #

gmapQi :: Int -> (forall d. Data d => d -> u) -> Natural -> u Source #

gmapM :: Monad m => (forall d. Data d => d -> m d) -> Natural -> m Natural Source #

gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural Source #

gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Natural -> m Natural Source #

Enum Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Enum

Ix Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Ix

Num Natural Source #

Note that Natural's Num instance isn't a ring: no element but 0 has an additive inverse. It is a semiring though.

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Num

Read Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Read

Integral Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Real

Real Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Real

Show Natural Source #

Since: base-4.8.0.0

Instance details

Defined in GHC.Internal.Show

Eq Natural Source # 
Instance details

Defined in GHC.Internal.Bignum.Natural

Ord Natural Source # 
Instance details

Defined in GHC.Internal.Bignum.Natural

TestCoercion SNat Source #

Since: base-4.18.0.0

Instance details

Defined in GHC.Internal.TypeNats

Methods

testCoercion :: forall (a :: Nat) (b :: Nat). SNat a -> SNat b -> Maybe (Coercion a b) Source #

TestEquality SNat Source #

Since: base-4.18.0.0

Instance details

Defined in GHC.Internal.TypeNats

Methods

testEquality :: forall (a :: Nat) (b :: Nat). SNat a -> SNat b -> Maybe (a :~: b) Source #

Lift Natural Source # 
Instance details

Defined in GHC.Internal.TH.Lift

Methods

lift :: Quote m => Natural -> m Exp Source #

liftTyped :: forall (m :: Type -> Type). Quote m => Natural -> Code m Natural Source #

type Compare (a :: Natural) (b :: Natural) Source # 
Instance details

Defined in GHC.Internal.Data.Type.Ord

type Compare (a :: Natural) (b :: Natural) = CmpNat a b

naturalCheck# :: Natural -> Bool# Source #

Check Natural invariants

naturalCheck :: Natural -> Bool Source #

Check Natural invariants

Useful constants

naturalZero :: Natural Source #

Zero Natural

naturalOne :: Natural Source #

One Natural

Predicates

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

Conversion with...

BigNat

naturalFromBigNat# :: BigNat# -> Natural Source #

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

naturalToBigNat# :: Natural -> BigNat# Source #

Convert a Natural into a BigNat#

Word

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

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.

Limbs

naturalFromWordList :: [Word] -> Natural Source #

Create a Natural from a list of Word

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.

Floating point

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

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

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

Addr#

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.

Comparison

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

Bit operations

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

naturalSetBit# :: Natural -> Word# -> Natural Source #

Since: ghc-internal-1.3

naturalSetBit :: Natural -> Word -> Natural Source #

Since: ghc-internal-1.3

naturalClearBit# :: Natural -> Word# -> Natural Source #

Since: ghc-internal-1.3

naturalClearBit :: Natural -> Word -> Natural Source #

Since: ghc-internal-1.3

naturalComplementBit# :: Natural -> Word# -> Natural Source #

Since: ghc-internal-1.3

naturalComplementBit :: Natural -> Word -> Natural Source #

Since: ghc-internal-1.3

Arithmetic

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.

Miscellaneous

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

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

base must be > 1