Interactive Educational Modules in
Scientific Computing

Rounding Error vs. Truncation Error

This module demonstrates the tradeoff between rounding error and truncation error when using finite-precision, floating-point arithmetic. The specific problem is computing the change in the surface area A of the Earth if its radius r = 6371 km changes by a given amount Δr. Two different formulas are used, one from geometry, ΔA = 4 π (r + Δr)2 − 4 π r 2, that is theoretically exact (assuming perfect real arithmetic), and the other a simple approximation derived from calculus, ΔA ≈ 8 π r Δr, whose accuracy depends on the amount by which the radius changes. For a relatively small change, the exact formula suffers substantial rounding error, whereas the approximate formula is very accurate. For a relatively large change, on the other hand, the exact formula does not suffer significant rounding error, whereas the approximate formula becomes very inaccurate.

The user first selects the precision to be used in the calculation, from one to sixteen decimal digits, and then selects an amount by which the Earth's radius is changed by dragging or clicking on the vertical scale. The number of correct digits in the results produced by the two formulas is indicated by the red (exact) and blue (approximate) bars.

Reference: Michael T. Heath, Scientific Computing, An Introductory Survey, 2nd edition, McGraw-Hill, New York, 2002. See Section 1.2, especially Example 1.1 on page 5 and Exercise 1.9 on page 43.

Developers: Nicholas Exner, Michael Ham, and Michael Heath