P
Pete Becker
Would this work for you:
http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm
No. It's from the superstitious school of floating-point math.
Its first sentence is "Floating point math is not exact." It presents
as evidence the example of converting the text "0.2" to floating-point,
which has nothing to do with floating-point math. And, of course, on a
system that uses decimal floating-point, this conversion is exact. And,
in contrast, converting "0.2" to an int is never exact. But nobody
advises using "approximately equal" for int values.
There are three kinds of programmers when it comes to floating-point math.
1. Those who don't know what its limitations are. They are surprised
when they don't get the results they expect, and they respond by making
up techniques (such as approximate comparisons) to fudge the results.
2. Those who know its limitations but aren't experts (I put myself in
this category). They can often get good results, and they know when
they need to call in someone with more expertise.
3. Those who know how floating-point math works. They tend to have PhDs. <g>
Java went the route of requiring exactness in floating-point math, and
it was a disaster. The language imposed IEEE 64-bit floating-point
math, with no extra bits allowed, for doubles. On PCs, this meant
setting the Intel math processor to 64-bit mode instead of its native
80-bit mode, and that makes it much slower. That speed loss was not
acceptable to people who do serious number crunching, so now Java has
two floating-point systems, one that's "strict" and one that's useful.