integer-gmp-1.0.0.0: Integer library based on GMP

GHC.Integer

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

# Documentation

data Integer Source

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 Ord Integer

# Construct `Integer`s

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.

Should rather be called `intToInteger`

# Conversion to other integral types

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

# Arithmetic operations

Add two `Integer`s

Subtract two `Integer`s from each other.

Multiply two `Integer`s

Negate `Integer`

Compute absolute value of an `Integer`

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

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

Simultaneous `divInteger` and `modInteger`.

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

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

Simultaneous `quotInteger` and `remInteger`.

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

# Comparison predicates

Not-equal predicate.

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

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

# Bit-operations

Bitwise AND operation

Bitwise OR operation

Bitwise XOR operation

Bitwise `NOT` operation

Shift-left operation

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

Arithmetic shift-right operation

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

Test if n-th bit is set.