HORIZON HASKELLDocslts/ghc-9.10.x248f8f02026-10-05Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · 248f8f0 · 2026-10-05

Moduleinteger-gmp-1.1Haskell2010

GHC.Integer.GMP.Internals

  • 7 types
  • 107 values
  • Packageinteger-gmp-1.1
  • Exports117
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceInteger.hs

The Integer type

5 declarations
datadata Integer
#

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 (i.e., fits into an Int), the IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing the positive or the negative value magnitude, respectively.

Invariant: IP and IN are used iff the value does not fit in IS.

Instances12Enum, Eq, Integral, Data, Num, Ord, …
  • Enum IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Integral IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Data IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Num
  • Ord IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Read IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Show IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Bits IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • PrintfArg IntegerDefined in base-4.20.2.0 · Text.Printf
patternpattern S# :: Int# -> Integer
#

Deprecated. Use IS constructor instead

Basic Integer operations

datadata Integer
#

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 (i.e., fits into an Int), the IS constructor is used. Otherwise IP and IN constructors are used to store a BigNat representing the positive or the negative value magnitude, respectively.

Invariant: IP and IN are used iff the value does not fit in IS.

Instances12Enum, Eq, Integral, Data, Num, Ord, …
  • Enum IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Enum
  • Eq IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Integral IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Data IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Data
  • Num IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Num
  • Ord IntegerDefined in ghc-bignum-1.3 · GHC.Num.Integer
  • Read IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Read
  • Real IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Real
  • Show IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Show
  • Ix IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Ix
  • Bits IntegerDefined in ghc-internal-9.1003.0 · GHC.Internal.Bits
  • PrintfArg IntegerDefined in base-4.20.2.0 · Text.Printf
valueabsInteger :: Integer -> Integer
#

Used to implement abs for the Num typeclass. This gives the absolute value of whatever integer is passed into it.

Example
Example1 expression
absInteger (-6)6
Example1 expression
abs (-6)6

Used to implement compare for the Integral typeclass. This takes two integers, and outputs whether the first is less than, equal to, or greater than the second.

Example
Example1 expression
compareInteger 2 10LT
Example1 expression
compare 2 10LT
valuedivInteger :: Integer -> Integer -> Integer
#

Used to implement div for the Integral typeclass. This performs integer division on its two parameters, truncated towards negative infinity.

Example
Example1 expression
10 `divInteger` 25
Example1 expression
10 `div` 2
valuedivModInteger :: Integer -> Integer -> (# Integer, Integer #)
#

Used to implement divMod for the Integral typeclass. This gives a tuple equivalent to

(div x y, mod x y)
Example
Example1 expression
divModInteger 10 2(5,0)
Example1 expression
divMod 10 2(5,0)
valueeqInteger :: Integer -> Integer -> Bool
#

Used to implement (==) for the Eq typeclass. Outputs True if two integers are equal to each other.

Example
Example1 expression
6 `eqInteger` 6True
Example1 expression
6 == 6True
valuegeInteger :: Integer -> Integer -> Bool
#

Used to implement (>=) for the Ord typeclass. Outputs True if the first argument is greater than or equal to the second.

Example
Example1 expression
5 `geInteger` 3True
Example1 expression
5 >= 3True
valuegtInteger :: Integer -> Integer -> Bool
#

Used to implement (>) for the Ord typeclass. Outputs True if the first argument is greater than the second.

Example
Example1 expression
5 `gtInteger` 3True
Example1 expression
5 > 3True
valueleInteger :: Integer -> Integer -> Bool
#

Used to implement (<=) for the Ord typeclass. Outputs True if the first argument is less than or equal to the second.

Example
Example1 expression
3 `leInteger` 5True
Example1 expression
3 <= 5True
valueltInteger :: Integer -> Integer -> Bool
#

Used to implement (<) for the Ord typeclass. Outputs True if the first argument is less than the second.

Example
Example1 expression
3 `ltInteger` 5True
Example1 expression
3 < 5True

Used to implement (-) for the Num typeclass. This gives the difference of two integers.

Example
Example1 expression
minusInteger 3 21
Example1 expression
(-) 3 21
valuemodInteger :: Integer -> Integer -> Integer
#

Used to implement mod for the Integral typeclass. This performs the modulo operation, satisfying

((x `div` y) * y) + (x `mod` y) == x
Example
Example1 expression
7 `modInteger` 31
Example1 expression
7 `mod` 31

Used to implement negate for the Num typeclass. This changes the sign of whatever integer is passed into it.

Example
Example1 expression
negateInteger (-6)6
Example1 expression
negate (-6)6
valueneqInteger :: Integer -> Integer -> Bool
#

Used to implement (/=) for the Eq typeclass. Outputs True if two integers are not equal to each other.

Example
Example1 expression
6 `neqInteger` 7True
Example1 expression
6 /= 7True
valueplusInteger :: Integer -> Integer -> Integer
#

Used to implement (+) for the Num typeclass. This gives the sum of two integers.

Example
Example1 expression
plusInteger 3 25
Example1 expression
(+) 3 25
valuequotInteger :: Integer -> Integer -> Integer
#

Used to implement quot for the Integral typeclass. This performs integer division on its two parameters, truncated towards zero.

Example
Example1 expression
quotInteger 10 25
Example1 expression
quot 10 25
valuequotRemInteger :: Integer -> Integer -> (# Integer, Integer #)
#

Used to implement quotRem for the Integral typeclass. This gives a tuple equivalent to

(quot x y, mod x y)
Example
Example1 expression
quotRemInteger 10 2(5,0)
Example1 expression
quotRem 10 2(5,0)
valueremInteger :: Integer -> Integer -> Integer
#

Used to implement rem for the Integral typeclass. This gives the remainder after integer division of its two parameters, satisfying

((x `quot` y) * y) + (x `rem` y) == x
Example
Example1 expression
remInteger 3 21
Example1 expression
rem 3 21

Used to implement signum for the Num typeclass. This gives 1 for a positive integer, and -1 for a negative integer.

Example
Example1 expression
signumInteger 51
Example1 expression
signum 51

Used to implement (*) for the Num typeclass. This gives the product of two integers.

Example
Example1 expression
timesInteger 3 26
Example1 expression
(*) 3 26

Additional Integer operations

Additional conversion operations to Integer

The BigNat type

5 declarations
datadata BigNat
#

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

Instances2Eq, Ord
  • Eq BigNatDefined in ghc-bignum-1.3 · GHC.Num.BigNat
  • Ord BigNatDefined in ghc-bignum-1.3 · GHC.Num.BigNat

Conversions to/from BigNat

BigNat arithmetic operations

BigNat logic operations

BigNat comparison predicates

Import/export functions

0 declarations

Compute size of serialisation

Export

Import