1 comment

[ 25.1 ms ] story [ 17.8 ms ] thread
If you dont know this much, you will shoot yourself in the foot, getting hard to track down errors. There a several other important things to know not mentioned in the article.

- Don't test for equality. Use "abs(a/b - 1) < epsilon", where epsilon is close to zero but larger than your accumulated rounding error. The least significant bits in the mantissa wiggle around quite a bit even when the values are supposed to be the same.

- Dont use binary floating point for money. Use a decimal representation. Python decimal is pretty good, but Java BigDecimal will bit you if you dont learn its peculiarities.

- Learn about NaN and Infinity. They are like Ice 9 (Vonnegut) and change everything they touch into themselves. You cant even test for them unless you know what you are doing.

Fore more read http://www.ibm.com/developerworks/java/library/j-jtp0114/ or links in the article.