integer-gmp-1.0.1.0: 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 | None
Language | Haskell2010

GHC.Integer

Contents

- Construct `Integer`s
- Conversion to other integral types
- Helpers for `RealFloat` type-class operations
- Arithmetic operations
- Comparison predicates
  - `Int#`-boolean valued versions of comparison predicates
- Bit-operations
- Hashing

Description

The `Integer` type.

This module exposes the portable `Integer` API. See GHC.Integer.GMP.Internals for the `integer-gmp`-specific internal representation of `Integer` as well as optimized GMP-specific operations.

Synopsis

- data Integer
- mkInteger :: Bool -> [Int] -> Integer
- smallInteger :: Int# -> Integer
- wordToInteger :: Word# -> Integer
- integerToWord :: Integer -> Word#
- integerToInt :: Integer -> Int#
- encodeFloatInteger :: Integer -> Int# -> Float#
- floatFromInteger :: Integer -> Float#
- encodeDoubleInteger :: Integer -> Int# -> Double#
- decodeDoubleInteger :: Double# -> (#Integer, Int##)
- doubleFromInteger :: Integer -> Double#
- plusInteger :: Integer -> Integer -> Integer
- minusInteger :: Integer -> Integer -> Integer
- timesInteger :: Integer -> Integer -> Integer
- negateInteger :: Integer -> Integer
- absInteger :: Integer -> Integer
- signumInteger :: Integer -> Integer
- divModInteger :: Integer -> Integer -> (#Integer, Integer#)
- divInteger :: Integer -> Integer -> Integer
- modInteger :: Integer -> Integer -> Integer
- quotRemInteger :: Integer -> Integer -> (#Integer, Integer#)
- quotInteger :: Integer -> Integer -> Integer
- remInteger :: Integer -> Integer -> Integer
- eqInteger :: Integer -> Integer -> Bool
- neqInteger :: Integer -> Integer -> Bool
- leInteger :: Integer -> Integer -> Bool
- gtInteger :: Integer -> Integer -> Bool
- ltInteger :: Integer -> Integer -> Bool
- geInteger :: Integer -> Integer -> Bool
- compareInteger :: Integer -> Integer -> Ordering
- eqInteger# :: Integer -> Integer -> Int#
- neqInteger# :: Integer -> Integer -> Int#
- leInteger# :: Integer -> Integer -> Int#
- gtInteger# :: Integer -> Integer -> Int#
- ltInteger# :: Integer -> Integer -> Int#
- geInteger# :: Integer -> Integer -> Int#
- andInteger :: Integer -> Integer -> Integer
- orInteger :: Integer -> Integer -> Integer
- xorInteger :: Integer -> Integer -> Integer
- complementInteger :: Integer -> Integer
- shiftLInteger :: Integer -> Int# -> Integer
- shiftRInteger :: Integer -> Int# -> Integer
- testBitInteger :: Integer -> Int# -> Bool
- hashInteger :: Integer -> Int#

# Documentation

data Integer #

Invariant: `Jn#` and `Jp#` are used iff value doesn't fit in `S#`

Useful properties resulting from the invariants:

-     abs (S# _) <= abs (Jp# _)

-     abs (S# _) <  abs (Jn# _)

Instances

Eq Integer # |
Methods (==) :: Integer -> Integer -> Bool (/=) :: Integer -> Integer -> Bool
Ord Integer # |
Methods compare :: Integer -> Integer -> Ordering (<) :: Integer -> Integer -> Bool (<=) :: Integer -> Integer -> Bool (>) :: Integer -> Integer -> Bool (>=) :: Integer -> Integer -> Bool max :: Integer -> Integer -> Integer min :: Integer -> Integer -> Integer

# Construct `Integer`s

mkInteger #

Arguments

:: Bool | sign of integer (`True` if non-negative)
-> [Int] | absolute value expressed in 31 bit chunks, least significant first (ideally these would be machine-word `Word`s rather than 31-bit truncated `Int`s)
-> Integer |

Construct `Integer` value from list of `Int`s.

This function is used by GHC for constructing `Integer` literals.

smallInteger :: Int# -> Integer #

Should rather be called `intToInteger`

wordToInteger :: Word# -> Integer #

# Conversion to other integral types

integerToWord :: Integer -> Word# #

integerToInt :: Integer -> Int# #

Truncates `Integer` to least-significant `Int#`

# Helpers for `RealFloat` type-class operations

encodeFloatInteger :: Integer -> Int# -> Float# #

floatFromInteger :: Integer -> Float# #

encodeDoubleInteger :: Integer -> Int# -> Double# #

decodeDoubleInteger :: Double# -> (#Integer, Int##) #

doubleFromInteger :: Integer -> Double# #

# Arithmetic operations

plusInteger :: Integer -> Integer -> Integer #

Add two `Integer`s

minusInteger :: Integer -> Integer -> Integer #

Subtract one `Integer` from another.

timesInteger :: Integer -> Integer -> Integer #

Multiply two `Integer`s

negateInteger :: Integer -> Integer #

Negate `Integer`

absInteger :: Integer -> Integer #

Compute absolute value of an `Integer`

signumInteger :: Integer -> Integer #

Return `-1`, `0`, and `1` depending on whether argument is negative, zero, or positive, respectively

divModInteger :: Integer -> Integer -> (#Integer, Integer#) #

Simultaneous `divInteger` and `modInteger`.

Divisor must be non-zero otherwise the GHC runtime will terminate with a division-by-zero fault.

divInteger :: Integer -> Integer -> Integer #

modInteger :: Integer -> Integer -> Integer #

quotRemInteger :: Integer -> Integer -> (#Integer, Integer#) #

Simultaneous `quotInteger` and `remInteger`.

Divisor must be non-zero otherwise the GHC runtime will terminate with a division-by-zero fault.

quotInteger :: Integer -> Integer -> Integer #

remInteger :: Integer -> Integer -> Integer #

# Comparison predicates

eqInteger :: Integer -> Integer -> Bool #

neqInteger :: Integer -> Integer -> Bool #

Not-equal predicate.

leInteger :: Integer -> Integer -> Bool #

gtInteger :: Integer -> Integer -> Bool #

ltInteger :: Integer -> Integer -> Bool #

geInteger :: Integer -> Integer -> Bool #

compareInteger :: Integer -> Integer -> Ordering #

## `Int#`-boolean valued versions of comparison predicates

These operations return `0#` and `1#` instead of `False` and `True` respectively. See PrimBool wiki-page for more details

eqInteger# :: Integer -> Integer -> Int# #

neqInteger# :: Integer -> Integer -> Int# #

leInteger# :: Integer -> Integer -> Int# #

gtInteger# :: Integer -> Integer -> Int# #

ltInteger# :: Integer -> Integer -> Int# #

geInteger# :: Integer -> Integer -> Int# #

# Bit-operations

andInteger :: Integer -> Integer -> Integer #

Bitwise AND operation

orInteger :: Integer -> Integer -> Integer #

Bitwise OR operation

xorInteger :: Integer -> Integer -> Integer #

Bitwise XOR operation

complementInteger :: Integer -> Integer #

Bitwise `NOT` operation

shiftLInteger :: Integer -> Int# -> Integer #

Shift-left operation

Even though the shift-amount is expressed as `Int#`, the result is undefined for negative shift-amounts.

shiftRInteger :: Integer -> Int# -> Integer #

Arithmetic shift-right operation

Even though the shift-amount is expressed as `Int#`, the result is undefined for negative shift-amounts.

testBitInteger :: Integer -> Int# -> Bool #

Test if n-th bit is set.

# Hashing

hashInteger :: Integer -> Int# #