Computer Arithmetic
For very large x, computing in floating point suffers catastrophic cancellation. Which rewrite computes it accurately?
- ACompute
- BCompute
- CUse double precision for x and subtract with the same formula
Show answer and explanation
Answer: A. Compute
and √x are nearly equal, so subtracting them directly cancels the leading digits. Multiplying numerator and denominator by gives, eliminating the subtraction of close values. equals 1 and is simply wrong. Computing in double precision from the start helps, but the same problem returns for larger x, so it is not a fundamental fix.
- A. Correct. The rewrite removes the subtraction and avoids cancellation.
- B. √(x + 1 − x) equals 1, which is not the original expression.
- C. Even in double precision, the problem returns for larger x.