This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Comparing doubles
- From: dewar at gnat dot com (Robert Dewar)
- To: dewar at gnat dot com, pkoning at equallogic dot com
- Cc: gcc at gcc dot gnu dot org, geoffk at geoffk dot org, lars at nocrew dot org
- Date: Sun, 7 Jul 2002 10:53:55 -0400 (EDT)
- Subject: Re: Comparing doubles
<<In any case, I don't understand these points. Certainly not the one
about subtraction. The only reasonable expectation is that the
implementation should produce results that conform to the standard to
which it is implemented. Whether addition is done by complement
followed by subtract, or subtract is done by complement and add, or
neither is true, is irrelevant so long as the answer is right.
>>
YOu missed my point.
First, what do we mean by "answer is right". Well the standard does not
define this. At one level, doing addition by complement followed by
subtract is obviously wrong since it does not give proper IEEE minus
zero semantics. At the other end, doing a subtraction *instead* of
an addition (which is what I was referring to) gives obviously drastically
wrong results. But the standard has little to say about what is right or
wrong, so we really can't turn to the standard in judging what is
reasonably conformant in this respect.
In the case of equality, it is reasonable to think that
a) you should be able to compare any valid fpt numbers
b) you should get true if and only if the numbers are the same
doing comparisons by subtraction violates both these expectations, so
at least on a machine where it is reasonably possible to do a) and b)
then any compiler which does not do a) and b) is in my view an incorrect
implementation.
Note that it is often possible to do floating-point comparisons in the
informal sense of a) and b) with integer comparison operations.
(the only glitch being signed zeros)