Comparing doubles

Tim Hollebeek tim@hollebeek.com
Sun Jul 7 18:06:00 GMT 2002


On Sun, Jul 07, 2002 at 09:09:45AM -0400, Paul Koning wrote:
> 
> As for compare, I don't claim to know the intricacies of IEEE NaN and
> all that, but surely on older float formats at least, compare is
> indeed internally just a subtract and test for zero?

The original suggestion, which seems to be missed by many, was
subtract _doubles_ and compare to _float_ zero.  Assuming that wasn't
an mistake, it is far, far different from standard equality (due to
the loss of precision from truncation).

Truncation before compare allows {a==b, b==c, c!=a}, and all other
sorts of unreasonable things.  Regardless of whether the standard
strictly requires it or not, it is reasonable to expect equality to be
an equivalence operation.

-Tim



More information about the Gcc mailing list