Take the 2-minute tour ×

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?

share|improve this question

1 Answer 1

up vote 9 down vote accepted

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.

share|improve this answer

Your Answer


