March Docs

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

ptypeBigIntBigInt = BigInt(Bool, List(Int))#

Functions

fnabsabs(n : BigInt) : BigInt#

Returns the absolute value of a BigInt.

fnaddadd(a : BigInt, b : BigInt) : BigInt#

Adds two BigInts.

fncomparecompare(a : BigInt, b : BigInt) : Int#

Compares two BigInts. Returns -1 (a < b), 0 (a == b), or 1 (a > b).

fndivdiv(a : BigInt, b : BigInt) : BigInt#

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.
fneqeq(a : BigInt, b : BigInt) : Bool#

Returns true if a equals b.

fnfrom_intfrom_int(n : Int) : BigInt#

Converts a native Int to BigInt.

fngtgt(a : BigInt, b : BigInt) : Bool#

Returns true if a > b.

fngtegte(a : BigInt, b : BigInt) : Bool#

Returns true if a >= b.

fnis_negativeis_negative(n : BigInt) : Bool#

Returns true if the BigInt is negative.

fnis_positiveis_positive(n : BigInt) : Bool#

Returns true if the BigInt is positive (> 0).

fnis_zerois_zero(n : BigInt) : Bool#

Returns true if the BigInt is zero.

fnltlt(a : BigInt, b : BigInt) : Bool#

Returns true if a < b.

fnltelte(a : BigInt, b : BigInt) : Bool#

Returns true if a <= b.

fnmod_mod_(a : BigInt, b : BigInt) : BigInt#

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`.
fnmulmul(a : BigInt, b : BigInt) : BigInt#

Multiplies two BigInts.

fnnegatenegate(a : BigInt) : BigInt#

Negates a BigInt.

fnoneone() : BigInt#

Returns BigInt one.

fnsubsub(a : BigInt, b : BigInt) : BigInt#

Subtracts b from a.

fnto_stringto_string(n : BigInt) : String#

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 `++`.
fnzerozero() : BigInt#

Returns BigInt zero.