Why is 1.0 unequal 1.0?

If your machine uses binary floating point arithmetic, and chances are that it does, you may eventually find yourself in the following situation:

0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1+0.1
You expect to see 1.0 as result, and indeed that is what you get. Now you compare this result to the constant 1.0, but surprisingly for many users, the result is 0. Appearantly, 1.0 is unequal 1.0 for TEAPOT.

This is not a bug in TEAPOT, in fact it is not a bug at all. The problem is, that 0.1 (1.0/10.0) does not have an exact representation in binary floating point arithmetic, similar to how 1.0/3.0 does not have an exact representation in decimal arithmetic (or binary, for that matter). As such, a value very close to 0.1 is used, but when displaying it, it will be rounded to 0.1. The result is obvious, adding this number which is a little different from 0.1 ten times leads to a result very close to but not quite 1.0. Since it is so close, displaying it rounded to only a few digits precision shows 1.0.

To solve the comparison problem, TEAPOT has the operator ~= (in contrast to the operator ==), which compares two floating point values apart from the last significant bit. Use this operator to compare the two values from above and the result will be 1, meaning they are about equal. Don't assume that a number which can be expressed with a finite number of decimal digits will be represented exactly in binary floating point arithmetic.