Floating-Point Arithmetic and Rounding Error
00 · Symbol Glossary
The integer base of the digit expansion, with . Decimal examples in this chapter use . The binary model uses . Read "" as "base beta."
The number of significant digits kept in a normal floating-point number. Precision is a count of digits, not a statement about a particular device. With and , every normal number has the shape .
The finite set of normal floating-point numbers determined by , , and the exponent bounds. Rounding is a map from a real number in range into . Read "" as "x is a floating-point number."
The gap between and the next larger number in . It is a property of the set , not of an algorithm. Linear Algebra 20 uses this same gap.
Half a machine epsilon under round-to-nearest: . A single rounding of a real in the normal range changes it by a relative amount of at most .
The floating-point number obtained by rounding the real into . Read "fl of x." For an operation , means the exact real result is formed and then rounded.
The real number, depending on the operands, for which the rounded result equals the exact result times , with . It is not a constant defect: each operation has its own .
and, when , . Unit roundoff controls the second of these for one rounding. Cancellation inflates the second while leaving the first small.
The amplification of relative perturbations through the map . A large value means the subtraction is sensitive. The matrix condition number in Linear Algebra 20 is the same idea for a linear map.
01 · A Finite Subset of the Reals
Exact real arithmetic has infinite precision. A calculation that keeps a fixed number of digits cannot. The object of this chapter is that restriction, written as a set of real numbers and a rounding map, together with the error bounds the map satisfies. Nothing below depends on a programming language. A four-digit decimal calculation done by hand is the same mathematical model as a binary system with a larger .
The practical distinction the bounds explain is this. Rounding to four significant digits moves it by a few hundredths, a small relative change. Subtracting two such rounded prices can move the difference by a large relative amount, because the digits that survived rounding are precisely the digits the two prices share. Later sections turn that observation into a theorem.
Fix integers , , and exponent bounds . A normal floating-point number is a real number
The integer is the integer significand. Equivalently, in scientific form,
so the leading digit is nonzero. The factor is the significand (or mantissa), and in this second writing is the exponent of the scientific form. The set of all such , together with , is denoted .
Plain language: keep a fixed number of digits, require the first digit to be nonzero, and attach a power of the base. Those rules name a finite list of real numbers, written , together with zero. A real that is not on the list is not a floating-point number, however close it sits to one that is.
The two displays are the same set. For and , the integer form is the scientific form . Normalization — the demand that , or equivalently — prevents the same real from being written with two different exponents inside . Without it, and would be two names for one number, and "the" gap between adjacent elements would be undefined.
In the binade the admissible step by , so adjacent elements of are spaced apart. The spacing is proportional to the magnitude. That is the structural fact behind every relative-error bound in this chapter.
Take , , and exponents wide enough that every number below is normal.
- At the successor in is , so the forward gap is . The predecessor is , one binade lower, where the gap is .
- At the successor is and the forward gap is . The predecessor is . Throughout the gap stays .
- The real lies strictly between and , so it is not an element of .
A price quoted near and a rate quoted near are not being recorded to the same absolute tolerance, even though both keep four digits.
For the leading digit of a normal number is necessarily . Describing then requires only the remaining bits; the set is unchanged. The binary64 normal numbers are exactly this model with , , , and . Then . The specification also fixes a tie-breaking rule, recorded in the next section. Subnormal numbers, which fill the gap below the smallest normal with constant absolute spacing, are not needed for the identities below; the bounds assume a normal result.
Suppose four decimal digits are in use, and a spread of is treated as "safely larger than the last digit" because the last digit near is .
Why it breaks: the gap at magnitude is , not . The real is not in , and both and are admissible roundings of nearby reals. A tolerance copied from the binade of does not apply in the binade of .
Consequence: an absolute error budget with no factor of is not a floating-point error budget. The quantity that is uniform across binades is the relative gap, computed next.
02 · Rounding and the Standard Model
is discrete. A real in the normal range is replaced by a nearby element of .
Let lie between the least and greatest positive elements of , and let be the adjacent elements of with . Round-to-nearest sets equal to whichever of , is closer to . On an exact tie either neighbor may be chosen; the binary64 rule chooses the neighbor whose integer significand is even. Chopping always chooses the neighbor toward .
The machine epsilon is the gap just above ,
For round-to-nearest the unit roundoff is half that gap,
For the running decimal system, and . For binary64, and .
Plain language: rounding sends a real to a neighboring entry of . Machine epsilon is the distance from to the next larger entry. Unit roundoff is half that distance, and it is the largest relative change one round-to-nearest step is allowed to make.
Linear Algebra 20 quotes for binary64. That number is , the gap. The rounding inequality in this chapter is stated with , which is half the gap when ties are broken by nearness. For chopping, the sharp constant is rather than ; every theorem below is the round-to-nearest case.
If lies in the open normal range, then there exists a real with
Equivalently, .
Plain language: a single rounding multiplies the true value by , and is at most the unit roundoff. The absolute error may grow with ; the relative error stays within .
Place in its binade. For some exponent , . The proof for is the same after changing sign, so take .
Read the gap. Adjacent elements of in this binade differ by . Round-to-nearest moves by at most half a gap, including on a tie: .
Divide by the smallest magnitude in the binade. The largest relative error occurs at the left endpoint, where may be as small as . Therefore
Rewrite as a factor. Set . The previous step is , and .
Unit roundoff is the smallest relative nudge near : half the step from to the next number in . The absolute step grows with the magnitude, and that relative nudge stays the size of .
Rounding each input, then operating, then rounding the result, is the whole of floating-point arithmetic. For inputs already in the first rounding is idle.
Let be one of , , , . Let , with in the division case, and assume lies in the normal range (no overflow and no underflow). Then there exists , depending on , , and , such that
In words: the computed result is the exact result, multiplied by a relative factor within one unit roundoff.
Plain language: the computed result of one addition, subtraction, multiplication, or division is the exact real result, then one rounding. That rounding is a relative factor within one unit roundoff, as long as the exact result stays inside the normal range.
The identity is not an approximation slogan. It is the previous theorem applied to the real number . Overflow (an exponent above ) and underflow (a result below the smallest normal) are excluded from the hypothesis because the rounded result then leaves the model: there is no of size at most for which the identity holds.
Compute with , , round-to-nearest.
The exact product splits as , , and . Adding these gives , then .
The fifth significant digit of is , so . The absolute discrepancy is . Hence
Since , one has , which is well below . The standard model guarantees only the coarser bound; this particular product lands closer.
The model does not say that a formula of several operations has relative error . Each operation contributes its own factor . Nor does it say that the operations remain associative.
Work in , , so the gap at is and . Let , , and , all three already in .
The two groupings. First, and . Second, the exact sum lies at distance from and at distance from , so . Then .
Why it breaks: each individual addition satisfies the standard model. The two expressions insert the rounding at different places. After has discarded the unit, no later addition can recover it.
Consequence: and are not interchangeable once results are required to lie in . A rearrangement is a different algorithm and needs its own error bound.
03 · Absolute and Relative Error
If is an approximation to a real , the absolute error is . When , the relative error is . Relative error is unchanged if and are scaled by the same nonzero constant. Absolute error is not.
Plain language: absolute error is the distance between the approximation and the true value. Relative error is that distance divided by the size of the true value, so scaling both numbers by the same nonzero constant leaves it unchanged.
The theorem of the previous section is a relative-error statement: one rounding produces , and therefore . An absolute tolerance copied from one magnitude to another has no justification in .
Suppose a computed value is above the true value.
- On a price , one has . In the four-digit decimal system this is below : the price has survived to better than a unit roundoff.
- On a one-day rate difference , the same absolute error gives . The computed difference has no correct digit. The absolute defect did not change; the denominator did.
Reporting " of error" without does not say whether the result is usable.
In binary64, . A notional of size is rounded.
Why it breaks: the absolute bound from the rounding theorem is , not . The number is dimensionless. Multiplying a cash amount by changes the unit from "relative" back to "currency."
Consequence: a control that treats as a currency tolerance accepts absolute errors a billion times larger than that control was meant to catch, as soon as the notional is .
04 · Catastrophic Cancellation
Subtraction of nearly equal floating-point numbers is often exact. The damage is older than the subtraction.
Let be nonzero and have the same scientific exponent, and assume does not underflow. Then , so .
Plain language: if two floating-point numbers share an exponent, their difference is already an element of , provided it does not underflow. The subtraction returns the exact difference, and the rounding factor on that operation is .
Write both numbers on the integer lattice of that binade. For a common exponent parameter , and with integers between and .
Subtract the integers. . The coefficient is an integer of absolute value at most , so it does not need a st digit.
Normalize if the leading digit vanished. If , the difference is already normal at this exponent. If the coefficient is smaller, lower the exponent until the leading digit is nonzero. Lowering the exponent shifts a shorter integer; it does not invent digits. The hypothesis that the result is still above the underflow threshold keeps the new exponent inside the range.
Conclude. equals an element of , so rounding changes nothing and the in the standard model is .
The binary statement extends past a single binade. If are binary floating-point numbers, , and does not underflow, then again . The extra room of a factor two is special to : the unit in the last place at most doubles when the exponent increases by one, and keeps on the same lattice as . This is Sterbenz's lemma. The decimal examples below need only the same-exponent form already proved.
Let be reals and , . Catastrophic cancellation is the situation in which is comparable to the absolute errors and , so that the relative error of as an approximation to is large, even though exactly.
Plain language: the stored difference can equal exactly and still be a poor stand-in for . The digits that separated the true values were dropped when each value was rounded, so the difference is assembled from what rounding discarded.
The condition number of the map makes the inflation quantitative. Perturb by a relative amount and by . The relative change in the difference satisfies
If , the right-hand side is at most with
When the denominator is small and is large. The subtraction did not become an inaccurate operation. The function became a sensitive function.
Cancellation here is shared leading digits wiping the difference. The stored values agree on the digits that were kept, so is built from the digits the two roundings already threw away.
Take , , . Let the true values be and , so .
The fifth digit of is , so . The fifth digit of is followed by a nonzero remainder, so under round-half-away-from-zero. Both inputs have absolute error , and both relative errors are about .
The stored numbers share an exponent. By the lemma, exactly. Against the true difference,
The relative error is several hundred times . The condition number explains the size: , and .
The same arithmetic is a spread of two quoted levels. The stored level keeps four digits; the spread lives in the digits the rounding already discarded. Measuring the spread's relative error against alone, with no factor , will call a bad spread acceptable.
A standard cure is to rewrite the expression so that the small result is not a difference of two rounded quantities. The quadratic formula is the classical case, and every step below is four-digit decimal arithmetic.
Record the exact roots. For , the discriminant is and its square root is just under . The smaller root is , and the product of the roots is .
Round the discriminant in four digits. . The fifth significant digit is , so . The subtraction has been lost: the gap at is , and is far below half a gap.
Evaluate the cancelling formula. . Then , so the computed smaller root is . The relative error against is .
Use the conjugate identity instead. For with , the smaller root equals . In four digits, is computed as and , which lies in . The absolute error is about , and the relative error is about , far below .
The algebra of the rewrite is worth one line, because it is the reason the second algorithm never subtracts. If , then
The left side subtracts two quantities that agree to six figures. The right side divides two quantities of moderate size. They are equal in real arithmetic and unequal in .
In the quadratic calculation, was exact, and in the two-level example was exact.
Why it breaks: the standard model applied to those subtractions gives . The zeros that appeared in the leading digits were already zeros in before the subtraction was performed. Sterbenz's setting, and the same-exponent lemma, describe an operation that returns its exact mathematical value.
Consequence: "carrying more guard digits through the subtraction" does not repair a difference whose error was committed when the operands were rounded. The repair is an algebraically equivalent expression whose condition number is moderate, as with .
05 · Truncation Error and Roundoff
Rounding is not the only discrepancy between a mathematical expression and the number that replaces it. Stopping a limit, a series, or a difference quotient introduces a second discrepancy that would be present even if every arithmetic operation were exact in .
Suppose a target value is replaced by a mathematical approximation , and is then evaluated in to produce . The truncation error is . The roundoff error is . The error that is actually observed splits as
The first summand is a statement about analysis in . The second is a statement about and is bounded using .
Plain language: truncation error is the distance between the mathematical shortcut and the target . It would remain if every arithmetic step were exact. Roundoff error is the further distance between the digit-limited value and that same shortcut.
Truncation is the formula cut short of the limit, series, or quotient that defines . Roundoff is the effect of a finite digit budget on the formula that was actually evaluated. The observed error adds the two.
The two summands typically move in opposite directions as a step shrinks. A first-order difference quotient has truncation of order and a roundoff contribution of order , because a difference of size is divided by after absolute noise of size about has entered the function values. Shrinking improves the first and degrades the second.
Name the target and the remainder. The target is , estimated by . Taylor's theorem with remainder gives for some between and , so
Take , where truncation dominates. The series sums to , and the unused remainder is smaller than . Four-digit rounding gives . Then . The observed absolute error is , matching from the truncation bound. Replacing by changed the quotient by only .
Take , where roundoff dominates. Here . The successor of is . Distance against distance puts closer to , so . The computed quotient is . Truncation is at most . The observed absolute error is , from rounding the numerator to zero in .
Check the roundoff budget. An absolute perturbation of size at most in the numerator, followed by division by , moves by at most about . For and this ceiling is , which is large enough to permit the computed value . For the same ceiling is , smaller than the truncation . The bound tells which term is in charge before the quotient is formed.
Differentiation, quadrature, and one-step methods for differential equations each produce a whose truncation tends to with , and a computed whose roundoff does not. Those chapters bound truncation by a Taylor expansion in and roundoff by the standard model above. The useful step balances the two terms in the split.
The four-digit quotient at has absolute error . Replacing the step by is proposed in order to "make the Taylor remainder negligible."
Why it breaks: the truncation bound does fall, from to under . The computed numerator falls below half a unit in the last place of and rounds to . The observed error rises from to .
Consequence: once exceeds , further reduction of is not a refinement of the approximation. The limiting value in exact arithmetic and the limiting value in are different objects.
06 · The Scalar Model Beside a Linear System
Every bound above concerns a scalar map. A linear system is a map on matrices and vectors. If and the data move by small relative amounts, the relative change in is controlled by times those amounts. Linear Algebra 20 states that theorem; the argument is not repeated here.
The scalar standard model supplies only the size of the perturbation. One rounding multiplies by with . A backward-stable elimination returns the exact solution of a nearby system whose relative perturbation is a modest multiple of , and passing to the forward error multiplies by :
up to the dimensional factors kept explicit in Linear Algebra 20. Moderate with small leaves digits intact. A condition number as large as can remove every digit while each arithmetic step still satisfies .
Section 04 is the same pattern with in place of . An exact subtraction and a large match a backward-stable factorization and a large : the operation met the model, and the function amplified it. The conjugate form of the quadratic changes the condition number. It leaves as it is.
07 · Exercises
Write as and look at the fifth significant digit. The absolute error is a difference of two fractions with denominator .
The expansion is . Five leading digits begin , so the fifth digit is and . Then , so . The relative error is . Since , this satisfies . For this system , and . The predecessor of in is and the successor is .
In the system , , with round-to-nearest (half away from zero when the discarded part is at least half a unit), compute . Give the absolute error and the relative error as exact fractions, and check them against . State and the two neighbors of in .
Expand and separately, add, then keep four significant digits. Compare the absolute discrepancy with times the exact product.
and . The exact product is . The fifth significant digit is , so . The absolute discrepancy is . Then . Because , one has , in agreement with the standard model. The model asserts existence of some such ; this product exhibits one.
In four-digit decimal round-to-nearest arithmetic, compute from the exact product. Exhibit a satisfying the standard model and show by a direct comparison, without appealing to the general proof.
With and , form and round to four significant digits before taking the square root. For the stable value use with that same rounded square root.
, which rounds to because the fifth digit is . The square root in four digits is . The cancelling formula returns . The true smaller root is , so the computed root has relative error . The conjugate form uses the same rounded square root: , which equals and lies in . Its absolute error is about and its relative error is about , below . The subtraction was exact; the information was lost when was replaced by .
For , compute the smaller root in four-digit decimal arithmetic by the cancelling quadratic formula, and again by the conjugate form . Compare both with the true smaller root, and state whether the subtraction of the two four-digit terms was itself inexact.
Bound the truncation by . Build from its Taylor polynomial far enough to round to four digits, then form . At the series already shows where sits between and .
At the truncation bound is . The partial sum . The tail is smaller than divided by , which is under , so and the truncation is under . Four-digit rounding gives because the fifth digit is . The quotient is , absolute error against the derivative . Rounding the exponential moved the quotient by about , so truncation dominates. At the truncation is at most . The series gives . The successor of is , and is closer to , so and the quotient is . The absolute error against the derivative is . Roundoff dominates.
Let estimate the derivative of at . In the four-digit decimal system, bound the truncation for and for , compute both rounded quotients, and say which of truncation or roundoff dominates at each step. Use the Taylor expansion with remainder, evaluated by hand.
08 · Summary
| Object | Statement |
|---|---|
| Normal set | with |
| Machine epsilon | gap just above |
| Unit roundoff | for round-to-nearest |
| One rounding | with at most in magnitude |
| Standard model | under the same bound, no over/underflow |
| Absolute vs relative | bounds relative error; absolute error scales with the magnitude |
| Exact cancellation | same-exponent differences in are exact if they do not underflow |
| Catastrophic cancellation | relative error inflated by , magnitudes over the difference |
| Truncation vs roundoff | and scale oppositely in |
| Link to linear systems | forward error carries a factor ; is proved in Linear Algebra 20 |
Next: Chapter 02 — Root-Finding Algorithms, which uses this model when a bracketed root is refined by bisection, Newton, and secant updates: each update is exact arithmetic plus a rounding factor , and the truncation of the iteration is a separate term.