FP comparisons, C, X86, and NaN's

Chris Lattner sabre@nondot.org
Sun Jun 20 01:44:00 GMT 2004


I'm trying to understand the standards relating to floating point
comparisons in C, particularly with respect to NaN's.  From my
interpretation of the whole mess, in C99, standard relational operations
(like X < Y) should trap on NaN's, including SNaNs.

When looking into this, I noticed that GCC compiles standard relational
comparisons to the fucom* instructions on the X86 target (which ignore
nans), but the ICC compiler compiles them to fcom* (which traps on nans).

Which is right?  Roger pointed out to me that there would be no reason for
the C99 isgreaterequal (and family) functions if comparisons didn't trap.
Based on this, I see two alternatives:

1. GCC has a bug, it should be producing fcom* instead of fucom*
2. C does not define whether or not standard relational operations trap.
   If this is the case, there is no bug in GCC.

Does anyone have any thoughts on this matter?

-Chris

-- 
http://llvm.cs.uiuc.edu/
http://www.nondot.org/~sabre/Projects/



More information about the Gcc mailing list