base-4.14.1.0: Basic libraries

GHC.Natural

Description

The arbitrary-precision Natural number type.

Note: This is an internal GHC module with an API subject to change. It's recommended use the Numeric.Natural module to import the Natural type.

Since: base-4.8.0.0

Synopsis

# The Natural number type

Warning: The internal implementation of Natural (i.e. which constructors are available) depends on the Integer backend used!

data Natural Source #

Type representing arbitrary-precision non-negative integers.

>>> 2^100 :: Natural
1267650600228229401496703205376


Operations whose result would be negative throw (Underflow :: ArithException),

>>> -1 :: Natural
*** Exception: arithmetic underflow


Since: base-4.8.0.0

Constructors

 NatS# GmpLimb# in [0, maxBound::Word] NatJ# !BigNat in ]maxBound::Word, +inf[Invariant: NatJ# is used iff value doesn't fit in NatS# constructor. NB: Order of constructors *must* coincide with Ord relation

#### Instances

Instances details
 # Since: base-4.8.0.0 Instance detailsDefined in GHC.Enum Methods # Since: base-4.8.0.0 Instance detailsDefined in GHC.Natural Methods # Since: base-4.8.0.0 Instance detailsDefined in GHC.Real Methods # Since: base-4.8.0.0 Instance detailsDefined in Data.Data Methodsgfoldl :: (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 #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 # # 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 detailsDefined in GHC.Num Methods # Since: base-4.8.0.0 Instance detailsDefined in GHC.Natural Methods # Since: base-4.8.0.0 Instance detailsDefined in GHC.Read Methods # Since: base-4.8.0.0 Instance detailsDefined in GHC.Real Methods # Since: base-4.8.0.0 Instance detailsDefined in GHC.Show MethodsshowList :: [Natural] -> ShowS Source # # Since: base-4.8.0.0 Instance detailsDefined in GHC.Ix Methodsrange :: (Natural, Natural) -> [Natural] Source #index :: (Natural, Natural) -> Natural -> Int Source #unsafeIndex :: (Natural, Natural) -> Natural -> Int Source #inRange :: (Natural, Natural) -> Natural -> Bool Source #rangeSize :: (Natural, Natural) -> Int Source # # Since: base-4.8.0 Instance detailsDefined in Data.Bits Methods # Since: base-4.8.0.0 Instance detailsDefined in Text.Printf Methods

Arguments

 :: [Word] value expressed in 32 bit chunks, least significant first -> Natural

Construct Natural value from list of Words.

This function is used by GHC for constructing Natural literals.

Test whether all internal invariants are satisfied by Natural value

This operation is mostly useful for test-suites and/or code which constructs Integer values directly.

Since: base-4.8.0.0

# Arithmetic

Natural Addition

Natural subtraction. May throw Underflow.

Natural subtraction. Returns Nothings for non-positive results.

Since: base-4.8.0.0

Natural multiplication

Compute greatest common divisor.

Compute least common multiple.

# Conversions

@since 4.X.0.0

Since: base-4.10.0.0

Construct Natural from Word value.

Since: base-4.8.0.0

Convert Int to Natural. Throws Underflow when passed a negative Int.

Try downcasting Natural to Word value. Returns Nothing if value doesn't fit in Word.

Since: base-4.8.0.0

Convert a Word# into a Natural

Built-in rule ensures that applications of this function to literal Word# are lifted into Natural literals.

Convert a Word# into a Natural

In base we can't use wordToNatural# as built-in rules transform some of them into Natural literals. Use this function instead.

# Modular arithmetic

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

Since: base-4.8.0.0