GHC.Natural
Copyright | (C) 2014 Herbert Valerio Riedel (C) 2011 Edward Kmett |
---|---|
License | see libraries/base/LICENSE |
Maintainer | [email protected] |
Stability | internal |
Portability | non-portable (GHC Extensions) |
Safe Haskell | None |
Language | Haskell2010 |
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
The Natural number type
Warning: The internal implementation of Natural
(i.e. which constructors are available) depends on the Integer
backend used!
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 |
NatJ# !BigNat |
in Invariant: |
Instances
Construct Natural
value from list of Word
s.
This function is used by GHC for constructing Natural
literals.
isValidNatural :: Natural -> Bool Source
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
plusNatural :: Natural -> Natural -> Natural Source
Natural
Addition
minusNatural :: Natural -> Natural -> Natural Source
Natural
subtraction. May throw
Underflow
.
minusNaturalMaybe :: Natural -> Natural -> Maybe Natural Source
Natural
subtraction. Returns Nothing
s for non-positive results.
Since: base-4.8.0.0
timesNatural :: Natural -> Natural -> Natural Source
Natural
multiplication
negateNatural :: Natural -> Natural Source
signumNatural :: Natural -> Natural Source
quotRemNatural :: Natural -> Natural -> (Natural, Natural) Source
quotNatural :: Natural -> Natural -> Natural Source
remNatural :: Natural -> Natural -> Natural Source
gcdNatural :: Natural -> Natural -> Natural Source
Compute greatest common divisor.
lcmNatural :: Natural -> Natural -> Natural Source
Compute least common multiple.
Bits
andNatural :: Natural -> Natural -> Natural Source
orNatural :: Natural -> Natural -> Natural Source
xorNatural :: Natural -> Natural -> Natural Source
bitNatural :: Int# -> Natural Source
testBitNatural :: Natural -> Int -> Bool Source
popCountNatural :: Natural -> Int Source
shiftLNatural :: Natural -> Int -> Natural Source
shiftRNatural :: Natural -> Int -> Natural Source
Conversions
naturalToInteger :: Natural -> Integer Source
@since 4.X.0.0
naturalToWord :: Natural -> Word Source
naturalToInt :: Natural -> Int Source
naturalFromInteger :: Integer -> Natural Source
Since: base-4.10.0.0
wordToNatural :: Word -> Natural Source
Construct Natural
from Word
value.
Since: base-4.8.0.0
intToNatural :: Int -> Natural Source
Convert Int
to Natural
. Throws Underflow
when passed a negative Int
.
naturalToWordMaybe :: Natural -> Maybe Word Source
Try downcasting Natural
to Word
value. Returns Nothing
if value doesn't fit in Word
.
Since: base-4.8.0.0
wordToNatural# :: Word# -> Natural Source
Convert a Word# into a Natural
Built-in rule ensures that applications of this function to literal Word# are lifted into Natural literals.
wordToNaturalBase :: Word# -> Natural Source
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 :: Natural -> Natural -> Natural -> Natural Source
"powModNatural b e m
" computes base b
raised to exponent e
modulo m
.
Since: base-4.8.0.0
© The University of Glasgow and others
Licensed under a BSD-style license (see top of the page).
https://downloads.haskell.org/~ghc/8.10.2/docs/html/libraries/base-4.14.1.0/GHC-Natural.html