Catastrophic cancellation 2026-10-14
Catastrophic cancellation occurs when subtraction of nearly equal approximations removes their matching leading digits and exposes earlier roundoff error. The subtraction can itself be exact on the stored operands: the information may already have been lost while obtaining them. Goldberg distinguishes this from cancellation of accurately known quantities, which can be harmless.[ref]
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html. Goldberg, 1991, §Cancellation
For , consider the single real-valued functionThe rationalization of a square-root difference proves equality in exact arithmetic. The two evaluations use the same input , but the direct version first forms a value near one and then subtracts one. The rearranged version keeps the small input in its numerator and divides by a denominator near two.
Direct and rationalized evaluation of a small square-root difference against a high-precision reference for the same binary64 inputs
. Details. For binary64
x = 1e-16, the rounded sum 1.0 + x is one, so sqrt(1.0 + x) - 1.0 is zero. The rationalized evaluation returns approximately . A 100-digit Decimal calculation using the exact stored input gives relative errors of one and about respectively. At x = 1e-12, the direct result is about , with relative error ; the rearranged result is about , with relative error .The plot uses
Decimal.from_float(x) to preserve the binary input exactly, computes at 100 decimal digits, and verifies the reference at 160 digits. Exact conversion of a stored binary value is documented by Python.[ref]https://docs.python.org/3.14/library/decimal.html#decimal.Decimal.from_float. Python 3.14 documentation, Decimal.from_float
Each error is , with the computed result converted exactly to Decimal before comparison. Hence the curves measure evaluation error for one common input, rather than a mixture of input conversion error and evaluation error. The plotted interval is far above the subnormal number range.The original problem is well conditioned with respect to relative changes in . Using the derivative and rationalization of a square-root difference, its relative condition number isIt tends to one as tends to zero. The direct evaluation instead introduces the intermediate difference with ; an error of order unit roundoff in is large relative to . This is a failure of the chosen algorithm's accuracy despite a small condition number for the same real-valued function. The rationalized evaluation avoids that intermediate catastrophic cancellation, retaining relative accuracy near the unit roundoff scale throughout the plotted interval. Recognizing this structure can improve a calculation far more than merely printing extra digits.
Floating-point arithmetic Created 2026-10-14 Updated 2026-10-14
Floating-point arithmetic represents a real number by a sign, a fixed number of significant digits, and a scale. It trades exactness for a compact representation spanning many orders of magnitude. The picture shows the essential compromise: with the same precision, large numbers have wider gaps between representable neighbors. Thus accuracy is naturally relative to magnitude, rather than a fixed distance along the number line.
Eight normalized four-bit binary values in each of three intervals, with gaps doubling from one eighth to one half
. Details. In radix , an integer at least two, a nonzero normalized value has the positional notationwhere the digits and exponent are integers. The parenthesized factor is the significand; counts all its significant digits, including the leading digit. Normalization means , so the same value has one such representation. The allowed exponents satisfy . Finite precision restricts the available digits, while the exponent bounds restrict the range. Zero needs a separate representation. This scales a digit string in positional notation by a power of its base.[ref]
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html. David Goldberg, What Every Computer Scientist Should Know About Floating-Point Arithmetic, §Floating-point Formats, 1991; Oracle's authorized edited reprint
For positive normalized values in , increasing the last digit by one gives the constant neighbor spacingAt the next scale, the spacing is multiplied by . In the binary numeral system with , the values in are ; those in are ; those in are . The respective gaps are , , and . Although absolute resolution deteriorates with magnitude, stays between and . This scale invariance is why floating-point arithmetic suits both microscopic and astronomical calculations.
The IEEE 754 binary64 format uses the binary numeral system with , including an implicit leading one for normalized values, and normal exponents . Its 64 stored binary digits comprise one sign digit, 11 exponent digits and 52 trailing significand digits. Subnormal numbers extend the range toward zero with a different leading-digit rule. In rounding to nearest, an operation returns the representable value closest to its exact result; a tie goes to the value whose last significant binary digit is even. Machine epsilon describes the gap just above one, whereas unit roundoff bounds a single relative rounding error in the normal range. These format and rounding rules are presented in MIT's floating-point lecture.[ref]
https://ocw.mit.edu/courses/18-335j-introduction-to-numerical-methods-spring-2019/2f313023ae3404bc217a81a31b227170_MIT18_335JS19_lec2.pdf. Per-Olof Persson, MIT 18.335J, Lecture 2: Floating-Point Arithmetic, the IEEE Standard, slides 6–9, 2019
Even an ordinary terminating decimal can require rounding in the binary numeral system. The rational number has the repeating positional notation . Every finite binary fraction has a reduced denominator that is a power of two, so the factor five in prevents an exact finite binary representation. In binary64, the exact stored values of three decimal literals and their computed sum areThe exact sum of the first two stored rational numbers is , halfway between two binary64 values. The even-last-digit tie rule rounds it upward. The printed result is
0.30000000000000004, one step above stored 0.3, so 0.1 + 0.2 == 0.3 is false. Both conversion of the inputs and rounding of the addition matter here.To reproduce the table on a Python installation using binary64, inspect exact fractions rather than only their printed decimal representations:Python's
import sys
assert (sys.float_info.radix, sys.float_info.mant_dig) == (2, 53)
for value in (0.1, 0.2, 0.3, 0.1 + 0.2):
print(repr(value), value.as_integer_ratio())
print(0.1 + 0.2 == 0.3) # Falseas_integer_ratio() returns a pair of integers whose quotient equals the stored finite value exactly.[ref]https://docs.python.org/3.14/library/stdtypes.html#float.as_integer_ratio. Python 3.14 documentation, float.as_integer_ratio
Exact rational numbers are also useful for checking floating-point arithmetic: a short decimal printout can hide the approximation being made.Historically, David Goldberg's March 1991 ACM Computing Surveys paper explained representation, rounding and catastrophic cancellation together with the IEEE standard's design choices. Oracle provides an authorized edited reprint. Its enduring lesson is practical: use the spacing to understand roundoff error, and inspect intermediate values when mathematically equivalent algorithms behave differently.[ref]
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html. Goldberg, 1991, reprint notice and §§Rounding Error, Cancellation
Stable construction of a Givens rotation 2026-10-14
For finite real numbers , a Givens rotation that annihilates is defined mathematically byHere
hypot means an evaluation of the Euclidean norm of designed to avoid unnecessary range failures in floating-point arithmetic. The zero case selects the identity matrix, avoiding division by zero. If , then ; if , then . Thus the retained component is nonnegative, including when . In exact arithmetic, and .Computing the square root of
a*a + b*b directly can fail even when the final norm is representable. In binary64 floating-point arithmetic, makes the squares overflow, whereas is finite. With the squares round to zero, although is representable. A range-safe hypot avoids these intermediate failures.The simple divisions still need care when is a subnormal number: rounding can cause large relative errors. For the smallest positive binary64 subnormal number , taking rounds to ; dividing by that rounded value gives , which is not an orthogonal matrix. For nonzero finite inputs, compute the coefficients before rescaling the norm:At least one scaled component has absolute value one, and . This construction keeps the coefficients meaningful even when rounding is severe. It cannot make an unrepresentably large finite, preserve an arbitrarily tiny against underflow, or repair inputs already rounded to zero. The row updates themselves can also overflow if their exact results exceed the available range.
LAPACK's
DLARTG uses scaling for numerical stability but a different sign convention: for it chooses and ; for it returns . Its block still has the lower-left minus sign. Do not combine its returned coefficients with an assumed nonnegative .[ref]DLARTG (LAPACK 3.12.1) by Edward Anderson. DLARTG, LAPACK 3.12.1, Purpose: block, signed R, scaling and zero-input cases; implementation lines 137–159
Subnormal number 2026-10-14
A subnormal number is a nonzero representable value smaller in magnitude than the least positive normalized value . Keep the exponent scale fixed at and allow a zero leading digit: the positive values are for integers . This fills the gap toward zero with constant absolute spacing, at the cost of fewer significant digits. Goldberg describes this gradual approach to zero and why it matters for differences of small numbers.[ref]
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html. Goldberg, 1991, §Denormalized Numbers
For binary64 the least positive normalized value is , and subnormal numbers are spaced by . With nearest rounding and gradual underflow enabled, an exact result with has absolute rounding error at most . A uniform relative bound by unit roundoff fails here: rounds to zero under the even-last-digit tie rule, giving relative error one. Machine epsilon measures resolution near one; it does not measure the distance from zero to the first positive value.
Unit roundoff 2026-10-14
For floating-point arithmetic with precision in radix and rounding to nearest, unit roundoff is the half-gap scale . If a nonzero exact real number lies in the normal finite range, its nearest rounded value satisfiesIndeed, the absolute distance to the nearest value is at most , and gives the bound. For a correctly rounded addition, subtraction, multiplication or division, apply this estimate to the exact result of that one operation on the stored operands. The bound does not include earlier roundoff error or automatically bound a whole algorithm. Results outside the finite range and tiny subnormal numbers require separate treatment. Rounding in a directed mode also changes the bound.[ref]
https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html. Goldberg, 1991, §§Relative Error and Ulps, Exactly Rounded Operations

