NaN's (was Re: FLOATING NULL?)
Jim Giles
jlg at cochiti.lanl.gov
Sun Jun 2 09:53:34 AEST 1991
In article <1991Jun1.214347.11696 at zoo.toronto.edu>, henry at zoo.toronto.edu (Henry Spencer) writes:
|> [...] It is simply a fact that in IEEE floating point, x!=x
|> is sometimes true, and optimizing it to `false' is a compiler bug.
I depends on how the `!=' operator is defined in C. The only relational
predicate that evaluates `true' under IEEE FP is `unordered'. So, if
`!=' is defined as `?<>' (in the IEEE notation: `?' stands for `unordered?'),
then it will evaluate `x!=x' as `true' if x is a NAN. However, if `!=' is
defined as `<>', then it will _always_ evaluate `x!=x' as `false'.
I can't find any specific reference in the ANSI C document which defines
which behaviour is appropriate. The ANSI/IEEE document Std 754-1985
(IEEE Standard for Binary Floating-Point Numbers) _recommends_ that the
_Fortran_ operator .NE. should be defined as `?<>'. Neither the Fortran
nor the C ANSI documents (proposals, in the case of Fortran) mention
the issue at all.
J. Giles
More information about the Comp.lang.c
mailing list