GHC.Integer.GMP.Internals

integer-gmp-1.1: Integer library based on GMP

Copyright | (c) Herbert Valerio Riedel 2014
License | BSD3
Maintainer | ghc-devs@haskell.org
Stability | provisional
Portability | non-portable (GHC Extensions)
Safe Haskell | Safe-Inferred
Language | Haskell2010

GHC.Integer.GMP.Internals

Contents

- The `Integer` type
  - Basic `Integer` operations
  - Additional `Integer` operations
  - Additional conversion operations to `Integer`
- The `BigNat` type
  - Conversions to/from `BigNat`
  - `BigNat` arithmetic operations
  - `BigNat` logic operations
  - `BigNat` comparison predicates
- Import/export functions
  - Compute size of serialisation
  - Export
  - Import

Description

Synopsis

- data Integer where
  - pattern S# :: Int# -> Integer
  - pattern Jn# :: BigNat -> Integer
  - pattern Jp# :: BigNat -> Integer
- isValidInteger# :: Integer -> Int#
- module GHC.Integer
- gcdInteger :: Integer -> Integer -> Integer
- gcdExtInteger :: Integer -> Integer -> (# Integer, Integer #)
- lcmInteger :: Integer -> Integer -> Integer
- sqrInteger :: Integer -> Integer
- powModInteger :: Integer -> Integer -> Integer -> Integer
- recipModInteger :: Integer -> Integer -> Integer
- wordToNegInteger :: Word# -> Integer
- bigNatToInteger :: BigNat -> Integer
- bigNatToNegInteger :: BigNat -> Integer
- data BigNat = BN# {
  - unBigNat :: BigNat#
  }
- type GmpLimb = Word
- type GmpLimb# = Word#
- type GmpSize = Int
- type GmpSize# = Int#
- isValidBigNat# :: BigNat -> Int#
- sizeofBigNat# :: BigNat -> GmpSize#
- zeroBigNat :: BigNat
- oneBigNat :: BigNat
- byteArrayToBigNat# :: ByteArray# -> GmpSize# -> BigNat
- wordToBigNat :: Word# -> BigNat
- wordToBigNat2 :: Word# -> Word# -> BigNat
- bigNatToInt :: BigNat -> Int#
- bigNatToWord :: BigNat -> Word#
- indexBigNat# :: BigNat -> GmpSize# -> GmpLimb#
- plusBigNat :: BigNat -> BigNat -> BigNat
- plusBigNatWord :: BigNat -> GmpLimb# -> BigNat
- minusBigNat :: BigNat -> BigNat -> BigNat
- minusBigNatWord :: BigNat -> GmpLimb# -> BigNat
- timesBigNat :: BigNat -> BigNat -> BigNat
- timesBigNatWord :: BigNat -> GmpLimb# -> BigNat
- sqrBigNat :: BigNat -> BigNat
- quotRemBigNat :: BigNat -> BigNat -> (# BigNat, BigNat #)
- quotRemBigNatWord :: BigNat -> GmpLimb# -> (# BigNat, GmpLimb# #)
- quotBigNatWord :: BigNat -> GmpLimb# -> BigNat
- quotBigNat :: BigNat -> BigNat -> BigNat
- remBigNat :: BigNat -> BigNat -> BigNat
- remBigNatWord :: BigNat -> GmpLimb# -> Word#
- gcdBigNat :: BigNat -> BigNat -> BigNat
- gcdBigNatWord :: BigNat -> Word# -> Word#
- shiftRBigNat :: BigNat -> Int# -> BigNat
- shiftLBigNat :: BigNat -> Int# -> BigNat
- testBitBigNat :: BigNat -> Int# -> Bool
- clearBitBigNat :: BigNat -> Int# -> BigNat
- complementBitBigNat :: BigNat -> Int# -> BigNat
- setBitBigNat :: BigNat -> Int# -> BigNat
- andBigNat :: BigNat -> BigNat -> BigNat
- xorBigNat :: BigNat -> BigNat -> BigNat
- popCountBigNat :: BigNat -> Int#
- orBigNat :: BigNat -> BigNat -> BigNat
- bitBigNat :: Int# -> BigNat
- isZeroBigNat :: BigNat -> Bool
- compareBigNatWord :: BigNat -> GmpLimb# -> Ordering
- compareBigNat :: BigNat -> BigNat -> Ordering
- eqBigNatWord :: BigNat -> GmpLimb# -> Bool
- eqBigNatWord# :: BigNat -> GmpLimb# -> Int#
- eqBigNat :: BigNat -> BigNat -> Bool
- eqBigNat# :: BigNat -> BigNat -> Int#
- gtBigNatWord# :: BigNat -> GmpLimb# -> Int#
- sizeInBaseBigNat :: BigNat -> Int# -> Word#
- sizeInBaseInteger :: Integer -> Int# -> Word#
- sizeInBaseWord# :: Word# -> Int# -> Word#
- exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word
- exportIntegerToAddr :: Integer -> Addr# -> Int# -> IO Word
- exportBigNatToMutableByteArray :: BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
- exportIntegerToMutableByteArray :: Integer -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word
- importBigNatFromAddr :: Addr# -> Word# -> Int# -> IO BigNat
- importIntegerFromAddr :: Addr# -> Word# -> Int# -> IO Integer
- importBigNatFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> BigNat
- importIntegerFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> Integer

# The `Integer` type

data Integer where Source #

Arbitrary precision integers. In contrast with fixed-size integral types such as `Int`, the `Integer` type represents the entire infinite range of integers.

Integers are stored in a kind of sign-magnitude form, hence do not expect two's complement form when using bit operations.

If the value is small (fit into an `Int`), `IS` constructor is used. Otherwise `Integer` and `IN` constructors are used to store a `BigNat` representing respectively the positive or the negative value magnitude.

Invariant: `Integer` and `IN` are used iff value doesn't fit in `IS`

Bundled Patterns

pattern S# :: Int# -> Integer | Deprecated: Use IS constructor instead
pattern Jn# :: BigNat -> Integer | Deprecated: Use IN constructor instead
pattern Jp# :: BigNat -> Integer | Deprecated: Use IP constructor instead

#### Instances

Instances details

Show Integer | Since: base-2.1
Instance details Defined in GHC.Show Methods showsPrec :: Int -> Integer -> ShowS Source # show :: Integer -> String Source # showList :: [Integer] -> ShowS Source #
Eq Integer |
Instance details Defined in GHC.Num.Integer Methods (==) :: Integer -> Integer -> Bool Source # (/=) :: Integer -> Integer -> Bool Source #
Ord Integer |
Instance details Defined in GHC.Num.Integer Methods compare :: Integer -> Integer -> Ordering Source # (<) :: Integer -> Integer -> Bool Source # (<=) :: Integer -> Integer -> Bool Source # (>) :: Integer -> Integer -> Bool Source # (>=) :: Integer -> Integer -> Bool Source # max :: Integer -> Integer -> Integer Source # min :: Integer -> Integer -> Integer Source #

isValidInteger# :: Integer -> Int# Source #

Deprecated: Use integerCheck# instead

## Basic `Integer` operations

module GHC.Integer

## Additional `Integer` operations

gcdInteger :: Integer -> Integer -> Integer Source #

Deprecated: Use integerGcd instead

gcdExtInteger :: Integer -> Integer -> (# Integer, Integer #) Source #

Deprecated: Use integerGcde instead

lcmInteger :: Integer -> Integer -> Integer Source #

Deprecated: Use integerLcm instead

sqrInteger :: Integer -> Integer Source #

Deprecated: Use integerSqr instead

powModInteger :: Integer -> Integer -> Integer -> Integer Source #

Deprecated: Use integerPowMod# instead

recipModInteger :: Integer -> Integer -> Integer Source #

Deprecated: Use integerRecipMod# instead

## Additional conversion operations to `Integer`

wordToNegInteger :: Word# -> Integer Source #

Deprecated: Use integerFromWordNeg# instead

bigNatToInteger :: BigNat -> Integer Source #

Deprecated: Use integerFromBigNat# instead

bigNatToNegInteger :: BigNat -> Integer Source #

Deprecated: Use integerFromBigNatNeg# instead

# The `BigNat` type

data BigNat Source #

A lifted BigNat

Represented as an array of limbs (Word#) stored in little-endian order (Word# themselves use machine order).

Invariant (canonical representation): higher Word# is non-zero.

As a consequence, zero is represented with a WordArray# whose size is 0.

Constructors

BN# |
Fields unBigNat :: BigNat#

#### Instances

Instances details

Eq BigNat |
Instance details Defined in GHC.Num.BigNat Methods (==) :: BigNat -> BigNat -> Bool Source # (/=) :: BigNat -> BigNat -> Bool Source #
Ord BigNat |
Instance details Defined in GHC.Num.BigNat Methods compare :: BigNat -> BigNat -> Ordering Source # (<) :: BigNat -> BigNat -> Bool Source # (<=) :: BigNat -> BigNat -> Bool Source # (>) :: BigNat -> BigNat -> Bool Source # (>=) :: BigNat -> BigNat -> Bool Source # max :: BigNat -> BigNat -> BigNat Source # min :: BigNat -> BigNat -> BigNat Source #

type GmpLimb = Word Source #

type GmpLimb# = Word# Source #

type GmpSize = Int Source #

type GmpSize# = Int# Source #

##

isValidBigNat# :: BigNat -> Int# Source #

Deprecated: Use bigNatCheck# instead

sizeofBigNat# :: BigNat -> GmpSize# Source #

Deprecated: Use bigNatSize# instead

zeroBigNat :: BigNat Source #

Deprecated: Use bigNatZero instead

oneBigNat :: BigNat Source #

Deprecated: Use bigNatOne instead

## Conversions to/from `BigNat`

byteArrayToBigNat# :: ByteArray# -> GmpSize# -> BigNat Source #

Deprecated: Use bigNatFromWordArray instead

wordToBigNat :: Word# -> BigNat Source #

wordToBigNat2 :: Word# -> Word# -> BigNat Source #

bigNatToInt :: BigNat -> Int# Source #

bigNatToWord :: BigNat -> Word# Source #

indexBigNat# :: BigNat -> GmpSize# -> GmpLimb# Source #

Deprecated: Use bigNatIndex# instead

## `BigNat` arithmetic operations

plusBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatAdd instead

plusBigNatWord :: BigNat -> GmpLimb# -> BigNat Source #

Deprecated: Use bigNatAddWord# instead

minusBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatSub instead

minusBigNatWord :: BigNat -> GmpLimb# -> BigNat Source #

Deprecated: Use bigNatSubWord# instead

timesBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatMul instead

timesBigNatWord :: BigNat -> GmpLimb# -> BigNat Source #

Deprecated: Use bigNatMulWord# instead

sqrBigNat :: BigNat -> BigNat Source #

Deprecated: Use bigNatSqr instead

quotRemBigNat :: BigNat -> BigNat -> (# BigNat, BigNat #) Source #

Deprecated: Use bigNatQuotRem# instead

quotRemBigNatWord :: BigNat -> GmpLimb# -> (# BigNat, GmpLimb# #) Source #

Deprecated: Use bigNatQuotRemWord# instead

quotBigNatWord :: BigNat -> GmpLimb# -> BigNat Source #

Deprecated: Use bigNatQuotWord# instead

quotBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatQuot instead

remBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatRem instead

remBigNatWord :: BigNat -> GmpLimb# -> Word# Source #

Deprecated: Use bigNatRemWord# instead

gcdBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatGcd instead

gcdBigNatWord :: BigNat -> Word# -> Word# Source #

Deprecated: Use bigNatGcdWord# instead

## `BigNat` logic operations

shiftRBigNat :: BigNat -> Int# -> BigNat Source #

Deprecated: Use bigNatShiftR# instead

shiftLBigNat :: BigNat -> Int# -> BigNat Source #

Deprecated: Use bigNatShiftL# instead

testBitBigNat :: BigNat -> Int# -> Bool Source #

Deprecated: Use bigNatTestBit# instead

clearBitBigNat :: BigNat -> Int# -> BigNat Source #

Deprecated: Use bigNatClearBit# instead

complementBitBigNat :: BigNat -> Int# -> BigNat Source #

Deprecated: Use bigNatComplementBit# instead

setBitBigNat :: BigNat -> Int# -> BigNat Source #

Deprecated: Use bigNatSetBit# instead

andBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatAnd instead

xorBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatXor instead

popCountBigNat :: BigNat -> Int# Source #

Deprecated: Use bigNatPopCount# instead

orBigNat :: BigNat -> BigNat -> BigNat Source #

Deprecated: Use bigNatOr instead

bitBigNat :: Int# -> BigNat Source #

Deprecated: Use bigNatBit# instead

## `BigNat` comparison predicates

isZeroBigNat :: BigNat -> Bool Source #

Deprecated: Use bigNatIsZero instead

compareBigNatWord :: BigNat -> GmpLimb# -> Ordering Source #

Deprecated: Use bigNatCompareWord# instead

compareBigNat :: BigNat -> BigNat -> Ordering Source #

Deprecated: Use bigNatCompare instead

eqBigNatWord :: BigNat -> GmpLimb# -> Bool Source #

Deprecated: Use bigNatEqWord# instead

eqBigNatWord# :: BigNat -> GmpLimb# -> Int# Source #

Deprecated: Use bigNatEqWord# instead

eqBigNat :: BigNat -> BigNat -> Bool Source #

Deprecated: Use bigNatEq instead

eqBigNat# :: BigNat -> BigNat -> Int# Source #

Deprecated: Use bigNatEq# instead

gtBigNatWord# :: BigNat -> GmpLimb# -> Int# Source #

Deprecated: Use bigNatGtWord# instead

# Import/export functions

## Compute size of serialisation

sizeInBaseBigNat :: BigNat -> Int# -> Word# Source #

Deprecated: Use bigNatSizeInBase# instead

sizeInBaseInteger :: Integer -> Int# -> Word# Source #

Deprecated: Use integerSizeInBase# instead

sizeInBaseWord# :: Word# -> Int# -> Word# Source #

Deprecated: Use wordSizeInBase# instead

## Export

exportBigNatToAddr :: BigNat -> Addr# -> Int# -> IO Word Source #

Deprecated: Use bigNatToAddr# instead

exportIntegerToAddr :: Integer -> Addr# -> Int# -> IO Word Source #

Deprecated: Use integerToAddr# instead

exportBigNatToMutableByteArray :: BigNat -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word Source #

Deprecated: Use bigNatToMutableByteArray# instead

exportIntegerToMutableByteArray :: Integer -> MutableByteArray# RealWorld -> Word# -> Int# -> IO Word Source #

Deprecated: Use integerToMutableByteArray# instead

## Import

importBigNatFromAddr :: Addr# -> Word# -> Int# -> IO BigNat Source #

Deprecated: Use bigNatFromAddr# instead

importIntegerFromAddr :: Addr# -> Word# -> Int# -> IO Integer Source #

Deprecated: Use integerFromAddr# instead

importBigNatFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> BigNat Source #

Deprecated: Use bigNatFromByteArray# instead

importIntegerFromByteArray :: ByteArray# -> Word# -> Word# -> Int# -> Integer Source #

Deprecated: Use integerFromByteArray# instead