Arbitrary precision is a form of computer arithmetic in which the number of digits available for a computation is determined by available resources rather than by a fixed machine format (Brent and Zimmermann 2010). Integer and rational operations can be exact, whereas floating-point operations use a finite working precision and generally incur roundoff error.
An arbitrary-precision integer is represented exactly and can grow as needed, subject to available memory. A nonzero integer can be stored using a sign
and a variable-length array of base-
digits
, where
, according to
The digits are commonly grouped into machine-word chunks. Arbitrary-precision rational numbers can similarly be stored as pairs of arbitrary-precision integers. Subject to resource exhaustion, operations on these integer and rational representations are exact.
The algorithms used for arithmetic depend on the operand size. Small operands can use machine arithmetic, while larger ones use methods such as long multiplication, Karatsuba multiplication, and the fast Fourier transform. Division can use long division or multiplication by an approximate reciprocal (Brent and Zimmermann 2010). A whole shifted inverse allows multiplication-based division to remain in the integer domain (Watt 2023).
For arbitrary-precision floating-point arithmetic, the working precision is selectable. Extra working digits and termination criteria are needed when a result does not have a finite expansion in the chosen radix. For example, the binary expansion
never terminates, although the rational number itself is represented exactly by a
numerator and denominator.