6
$\begingroup$

In http://en.wikipedia.org/wiki/Floating_point#Addition_and_subtraction, it gives an example about cancellation problem in float-point numbers, see

enter image description here

I don't understand why it is written :

The best representation of this difference is e = -1; s=4.877000, which differs more than 20%.....

In this example, it uses IEEE 754 decimal32 format.

Could someone explain the idea about cancellation problem in float-point numbers as this example want to illustrate?

$\endgroup$

1 Answer 1

10
$\begingroup$

The point they are making is that if you compute the difference 123457.1467 - 123456.659 = 0.4877 then you get an answer that seems to be quite different than the difference 123457.1 - 123456.7 = 0.4 that you get by subtracting the rounded numbers. The ~20% figure is because 0.4877 is more than 20% larger than 0.4.

This example shows that if you subtract two numbers that are very close to each other in the sense of small relative difference, then if you use floating point arithmetic you might have a bad time. This means that sometimes it is worthwhile to re-organize your calculations in ways that are mathematically equivalent but which differ in their floating point friendliness.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.