This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Comparing doubles
> Lars Brinkhoff <lars@nocrew.org> writes:
> > would it be acceptable for a GCC back end to compare two doubles
> > by subtracting them, converting the result to float, and then
> > compare the result against zero?
Geoff Keating <geoffk@geoffk.org> writes:
> If you define __STDC_IEC_559__, no.
That is now the case.
> Otherwise, you can do whatever you like, although it might give a
> less-than-useful FP implementation.
Alan Lehotsky <apl@alum.mit.edu> writes:
> I don't quite remember what PDP10 doubles were like, but if you
> don't have NANs, then using subtraction is probably a viable
> approach.
PDP-10 doubles are just floats with one more word of mantissa. There
are no NANs (nor infinities or -0). Floating-point numbers have the
property that (when normalized) they can be compared using the normal
integer-comparing instructions.
> The problem with using subtract is that you may [...] have an
> undetected underflow interpreted as equality when it isn't.
That is understood.
Mark Hahn <hahn@physics.mcmaster.ca> writes:
> calling the inputs "double" would seem extremely dishonest then...
Somewhat devious, yes, but not extremely dishonest, really?
--
Lars Brinkhoff http://lars.nocrew.org/ Linux, GCC, PDP-10,
Brinkhoff Consulting http://www.brinkhoff.se/ HTTP programming