Theorem 11

When subtracting two floating-point numbers x - y, we usually lose some precision, especially if x and y are very close. However, under certain conditions where x and y are close but not too close, a guard digit allows us to perform an exact subtraction - specifically, when:

Detecting subtraction errors

We can create a rudimentary mechanism for detecting subtraction errors by scaling up the values before we subtract them, then scaling down the difference by the same factor.

Loading TypeScript...

Proof

If and have the same exponent, then certainly is exact. Otherwise, from the condition of the theorem, the exponents can differ by at most . Scale and interchange x and y if necessary so that 0 y x, and x is represented as x0.x1 ... xp - 1 and y as 0.y1 ... yp. Then the algorithm for computing x y will compute x - y exactly and round to a floating-point number. If the difference is of the form 0.d1 ... dp, the difference will already be p digits long, and no rounding is necessary. Since x 2y, x - y y, and since y is of the form 0.d1 ... dp, so is x - y.

Was this page helpful?