Floating-point error
Weeks 1-2You can explain why a computer's answer differs from the exact one and estimate how big the gap is. You can also rewrite a formula to dodge a dangerous subtraction.
- Compute both absolute and relative error for a rounded value.
- Spot catastrophic cancellation when two nearly equal numbers are subtracted.
- Rewrite the quadratic formula to keep the small root accurate.
Worked example
True value 2.71828, computed value 2.718. Find the relative error.
- Absolute error = 0.00028
- Divide by the true value: 0.00028 / 2.71828
AnswerAbout 0.0103%
Most common mistakeQuoting the absolute error 0.00028 as if it were the relative error: the same gap is negligible near 2.7 and enormous near 0.001.