Consider second-order centered differences for calculating the first and second derivatives of f(x) = eˣ at x = 0. Ideally, both derivatives equal 1. The following table shows results in single precision (~7 decimal digits in the mantissa):

Single Precision – Numerical Instability

h f′(x) ≃ (f(x+h)−f(x−h))/2h f″(x) ≃ (f(x+h)−2f(x)+f(x−h))/h²
10⁻¹ 1.175201178 1.086161137
10⁻² 1.001667619 1.000839472
10⁻³ 1.000016928 1.000165939
10⁻⁴ 1.000017047 1.013279080
10⁻⁵ 1.000166059 0.000000000
10⁻⁶ 1.001358151 0.000000000
10⁻⁷ 0.983476758 −59604.6601

Reducing h by a factor of 10 initially improves accuracy, but for very small h, precision suddenly deteriorates, especially for the second derivative.

Double Precision – Numerical Instability

h f′(x) f″(x)
10⁻² 1.00001666674999212 1.00000833336055805
10⁻³ 1.00000016666668134 1.00000000166688974
10⁻⁴ 1.00000000166688974 1.00000000001210232
10⁻⁵ 1.00000000001210232 0.99999999997324440
10⁻⁶ 0.99999999997324440 0.99999999947364393
10⁻⁷ 0.99999999947364393 0.99999999392252880
10⁻⁸ 0.99999999392252880 1.00000002722921955
10⁻⁹ 1.00000002722921955 1.00000008274037078
10⁻¹⁰ 1.00000008274037078 1.00000008274037078
10⁻¹³ 0.99975583367495335 111.022302462515597
10⁻¹⁵ 1.05471187339389871 0.00000000000000000
10⁻¹⁷ 0.00000000000000000 −11102230246.251562

When h is too small, subtracting nearly equal numbers destroys significant digits, drastically affecting results. Care must be taken to choose h appropriately and avoid excessively small values.

Last modified: Saturday, 15 November 2025, 2:21 AM