BigInt

The BigInt module provides arbitrary precision integer arithmetic. BigInts can represent integers of any size, limited only by available memory.

Requires Import

Unlike core modules, BigInt requires an explicit import to use.

Creating BigInts

BigInt.from-int
Int -> BigInt
Creates a BigInt from a regular integer.
big = BigInt.from-int 1000000
BigInt.parse
String -> BigInt
Parses a string representation of a large integer.
huge = BigInt.parse "123456789012345678901234567890"

Arithmetic Operations

BigInt.add
BigInt -> BigInt -> BigInt
Adds two BigInts.
BigInt.sub
BigInt -> BigInt -> BigInt
Subtracts two BigInts.
BigInt.mul
BigInt -> BigInt -> BigInt
Multiplies two BigInts.
BigInt.div
BigInt -> BigInt -> BigInt
Integer division of two BigInts.
BigInt.mod
BigInt -> BigInt -> BigInt
Returns the remainder after division.
BigInt.pow
BigInt -> Int -> BigInt
Raises a BigInt to an integer power.
base = BigInt.from-int 2
result = BigInt.pow base 100
println (BigInt.to-str result)
# => "1267650600228229401496703205376"
BigInt.abs
BigInt -> BigInt
Returns the absolute value.
BigInt.neg
BigInt -> BigInt
Negates a BigInt.
BigInt.gcd
BigInt -> BigInt -> BigInt
Returns the greatest common divisor.

Comparison

BigInt.eq? / BigInt.ne?
BigInt -> BigInt -> Bool
Tests equality or inequality.
BigInt.lt? / BigInt.gt? / BigInt.le? / BigInt.ge?
BigInt -> BigInt -> Bool
Comparison operators.
BigInt.compare
BigInt -> BigInt -> Int
Returns -1, 0, or 1 for less than, equal, or greater than.

Predicates

BigInt.even? / BigInt.odd?
BigInt -> Bool
Tests if the BigInt is even or odd.
BigInt.positive? / BigInt.negative? / BigInt.zero?
BigInt -> Bool
Tests the sign of a BigInt.

Conversion

BigInt.to-int
BigInt -> Int
Converts to a regular integer. May overflow for large values.
BigInt.to-str
BigInt -> String
Converts to a string representation.