This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Comparing doubles
- From: Paul Koning <pkoning at equallogic dot com>
- To: dewar at gnat dot com
- Cc: geoffk at geoffk dot org, lars at nocrew dot org, gcc at gcc dot gnu dot org
- Date: Sun, 7 Jul 2002 09:09:45 -0400
- Subject: Re: Comparing doubles
- References: <20020706145326.B4B69F28EB@nile.gnat.com>
Excerpt of message (sent 6 July 2002) by Robert Dewar:
> > If you define __STDC_IEC_559__, no. Otherwise, you can do whatever
> > you like, although it might give a less-than-useful FP implementation.
>
> Well by this viewpoint, you can implement addition by doing a subtraction.
> Although a fully formal view of the standard might be consistent with this
> approach, in practice we expect + to do an addition, and we expect equality
> to do an equality operation, both in the usually understood informal meanings
> of the terms, i.e. + translates to a floating-point add, and = translates
> to a floating-point equals. Doing floating-point equality by subtraction
> and test for zero is just too far from this expectation on any modern
> machine.
I don't think Lars was talking about a modern machine... :-)
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.
Given that floating point negate can always be done exactly, I don't
see any reason why an implementation couldn't map subtract into add or
vice versa.
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? Or a normalize
(if applicable) and bitwise compare? (The latter is definitely the
case on the CDC 6600, to use an old example.)
paul