Copyright | (C) 2014 Herbert Valerio Riedel (C) 2011 Edward Kmett |
---|---|
License | see libraries/base/LICENSE |
Maintainer | libraries@haskell.org |
Stability | internal |
Portability | non-portable (GHC Extensions) |
Safe Haskell | None |
Language | Haskell2010 |
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: 4.8.0.0
Synopsis
- data Natural
- mkNatural :: [Word] -> Natural
- isValidNatural :: Natural -> Bool
- plusNatural :: Natural -> Natural -> Natural
- minusNatural :: Natural -> Natural -> Natural
- minusNaturalMaybe :: Natural -> Natural -> Maybe Natural
- timesNatural :: Natural -> Natural -> Natural
- negateNatural :: Natural -> Natural
- signumNatural :: Natural -> Natural
- quotRemNatural :: Natural -> Natural -> (Natural, Natural)
- quotNatural :: Natural -> Natural -> Natural
- remNatural :: Natural -> Natural -> Natural
- gcdNatural :: Natural -> Natural -> Natural
- lcmNatural :: Natural -> Natural -> Natural
- andNatural :: Natural -> Natural -> Natural
- orNatural :: Natural -> Natural -> Natural
- xorNatural :: Natural -> Natural -> Natural
- bitNatural :: Int# -> Natural
- testBitNatural :: Natural -> Int -> Bool
- popCountNatural :: Natural -> Int
- shiftLNatural :: Natural -> Int -> Natural
- shiftRNatural :: Natural -> Int -> Natural
- naturalToInteger :: Natural -> Integer
- naturalToWord :: Natural -> Word
- naturalToInt :: Natural -> Int
- naturalFromInteger :: Integer -> Natural
- wordToNatural :: Word -> Natural
- intToNatural :: Int -> Natural
- naturalToWordMaybe :: Natural -> Maybe Word
- wordToNatural# :: Word# -> Natural
- wordToNaturalBase :: Word# -> Natural
- powModNatural :: Natural -> Natural -> Natural -> Natural
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: 4.8.0.0
NatS# GmpLimb# | in |
NatJ# !BigNat | in Invariant: |
Instances
isValidNatural :: Natural -> Bool Source #
Arithmetic
negateNatural :: Natural -> Natural Source #
signumNatural :: Natural -> Natural Source #
Bits
bitNatural :: Int# -> Natural Source #
popCountNatural :: Natural -> Int Source #
Conversions
naturalToInteger :: Natural -> Integer Source #
Since: 4.12.0.0
naturalToWord :: Natural -> Word Source #
naturalToInt :: Natural -> Int Source #
naturalFromInteger :: Integer -> Natural Source #
Since: 4.10.0.0
intToNatural :: Int -> Natural Source #
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 #
"
" computes base powModNatural
b e mb
raised to
exponent e
modulo m
.
Since: 4.8.0.0