First page Back Continue Last page Overview Text
Notes:
Let's work in base 10, and keep 4 digits of precision. If I write ¼ I can express it as 0.25. If I then decide to multiply by 4 I get “5 * 4 is 20, carry the 2. 2 * 4 is 8 add the two that's 10 so we get 1.0”.
But suppose I try to write out 1/3. The real answer is 0.333333 and so on. The best I can do is an approximate answer of 0.3333. If I try multiplying that by 3, “well, 3 * 3 is 9, nothing to carry so I get 0.9999”. Which is NOT the same as 1.
It's tempting to think that somehow the floating point calculations introduced errors, but that's not really true! If you pay attention, the floating point multiplication was exact, it was expressing the number 1/3 in decimal that was approximate. This is called “Representation Error”. There are just some numbers like 1/3 that you can't work with accurately in decimal floating point.
If you think about it, you can probably figure out what set of numbers suffer from representation error. In base 2 (binary) numbers like 1/2, 1/4, and 1/8 are all ok, but 1/5 and 1/3 will fail. In base 10 (decimal) numbers like 1/5 are OK, but still not 1/3.
Now for the big secret. Decimal fp is no more or less subject to calculation errors than binary fp. But it just so happens that people like to use numbers that can be expressed exactly in decimal. We're much more likely to want to work with 2.67 than with 752/123. Binary fp is great for carpentry in english units: “I need a board that's 22 and 5/16 inches”, but not for most other endevors. Decimal fp fits the numbers that we use!