Arbitrary-precision integer Created 2026-10-20 Updated 2026-11-05
An arbitrary-precision integer stores an integer using a variable number of machine words. Unlike a fixed-width integer, it grows when more binary digits are needed. The sign and a finite sequence of base- digits represent its exact value.
For example, the integer requires hundreds of bits but no rounding. Arbitrary-precision integer arithmetic operates on these representations; it is distinct from approximate floating-point arithmetic. Memory and computation still impose practical bounds, so arbitrary precision does not mean infinite available storage.
Arbitrary-precision integer arithmetic Created 2026-10-20 Updated 2026-11-05
Arbitrary-precision integer arithmetic performs exact addition, subtraction, multiplication, and integer division using as many machine words as the value requires. A typical representation stores a sign and digits in base , with each digit occupying one machine word. Carries propagate between words just as in written decimal arithmetic.
For example, can be stored exactly even when a single machine integer has only bits. The attainable size is limited by memory and execution time, rather than a fixed numeric range. The cost grows with the number of bits, so an arithmetic operation on a large value cannot automatically be counted as constant time.
Relevant locators: remainder %, gcd, isValidInt and toInt. Scala's BigInt provides arbitrary-precision integer arithmetic; representability must be checked before conversion to a fixed-width integer because narrowing conversion need not preserve the exact value. The archived API corroborates the operations used in the solution without claiming a particular installed Oxford course library version.