Every computation on a computer introduces small errors because real numbers must be stored in finite precision. The key guarantee: the relative error of representing any real number is bounded by machine epsilon. This simple fact explains the mysterious finite difference behavior from Chapter 1 — and understanding it is the first step toward writing robust numerical code.
We need to represent all real numbers — from Avogadro’s number (6.02×1023) to Planck’s constant (6.63×10−34) — using finite resources. The solution is floating-point arithmetic: a finite set of numbers F that approximates the real line R, with a guaranteed bound on the relative error of the approximation.
The key fact is this: for any real number x, its floating-point representation fl(x) satisfies
where μ is machine epsilon (or unit roundoff). This says that floating-point representation introduces a small relative error — the same relative accuracy whether x is tiny or huge.
Single precision gives about 7 decimal digits of accuracy; double precision gives about 16 decimal digits. This means that two real numbers that agree to 16 significant digits will have the same double-precision representation. We will see exactly how these bits encode numbers when we study IEEE 754 representation.
Solving the Mystery: The Finite Difference Trade-off¶
In the previous chapter, we observed that finite difference errors increase for very small step sizes. Now we have the tools to explain why.
The round-off term 2μ∣f(x)∣/h grows as h→0 because we are subtracting nearly equal numbers. The absolute error of f(x+h)−f(x) stays roughly constant at (∣f(x+h)∣+∣f(x)∣)μ, but dividing by h amplifies it. More generally, subtracting nearly equal floating-point numbers destroys relative accuracy — this is called catastrophic cancellation.