Peter said:
Thats exactly my point, the 2 doubles *must* have the same bit pattern. In
other words, this is guarenteed to fail unless 64-bit double precison or
rounded 32-bit precision is involved (the output is self explanatory):
I have no idea what point you're trying to make here. I made the simple
statement that two doubles are equal if their representations have the
same bit pattern. It doesn't matter whether you got those two values
from doubles, floats, or ints. If they hold the same bit pattern they
are equal, and that is a meaningful and useful definition of equality*.
The fact that doing a computation in two different ways can produce
results that are not equal is irrelevant. Remember, all this started
from your assertion that "comparing doubles IN ANY WAY is an intensive
CPU operation [emphasis added]." That is not true, because you can
meaningfully compare doubles by treating them as suitably sized integral
values and comparing them as such. That is not an intensive CPU operation.
If your point is simply that doing what looks like the same computation
in two different ways can produce different results, then you're wasting
everyone's time, because that was established much earlier in this thread.
*For the nitpickers: yes, if the values are NaNs they are supposed to
compare unequal. And, of course, there are some values that sometimes
have multiple representations (for example, 0 and -0 are distinct values
that compare equal), so it is not true that two values are equal only if
they have the same bit pattern. But that's a completely different
discussion.