BigInt
BigInt module: arbitrary-precision integers.
Representation: BigInt(sign, digits) where sign : Bool — true = non-negative, false: negative digits : List(Int) — little-endian base-10000 digit list (least significant limb first) BigInt(true, Nil) represents zero.
Base 10000 is convenient: each limb stores 4 decimal digits, so to_string is straightforward without requiring integer logarithms.
Interface implementations: impl Eq(BigInt) — eq/2, == impl Ord(BigInt) — compare/2, < impl Show(BigInt) — show/1
Types
Functions
Compares two BigInts. Returns -1 (a < b), 0 (a == b), or 1 (a > b).
Divides a by b. Uses truncation toward zero: div(-17, 3) == -5, div(17, -3) == -5, div(-17, -3) == 5. Panics if b is zero.
**Limitation:** only single-limb divisors (|b| < `base()`, roughly 10^9)
are supported in the current implementation. Multi-limb divisors raise
`BigInt.div: multi-limb divisor not yet supported` — this is a loud
failure, not a silent wrong result, but callers must guard against it
until long division lands. Most practical use cases (dividing by small
denominators, modular arithmetic) fit within the limb bound.Computes a mod b (truncated modulo, same sign as a). The identity a == div(a, b) * b + mod_(a, b) always holds. Examples: mod_(-17, 3) == -2, mod_(17, 3) == 2. Panics if b is zero.
**Limitation:** only single-limb divisors (|b| < `base()`, roughly 10^9)
are supported. Multi-limb divisors raise
`BigInt.mod: multi-limb divisor not yet supported`.Converts a BigInt to its decimal string representation.
The digits are stored in base 10^4 (little-endian), so each limb
contributes 4 decimal characters (with leading zeros on all but the
most-significant limb). Pieces are collected into a list and
`string_join`-ed once at the end, making the routine O(number of
limbs) rather than the quadratic behaviour of repeated `++`.