Re: Question on performance
On Oct 18 2010, Vincent Lefevre wrote:
>What I meant is that isnan() and x != x can be seen as equivalent
>even if __STDC_IEC_559__ is 1.
Don't you mean 'is not'?
No. It seems clear that isnan() and x != x can be seen as equivalent
if __STDC_IEC_559__ is not 1, since on non-NaN values both are false,
and on NaN values, the behavior is implementation-dependent. So, an
implementation may specify its behavior so that they are equivalent.
As I said, unless the implementation defines __STDC_IEC_559__ to be 1,
the latter is UNDEFINED behaviour, unlike the former.
The point is that you are operating on values outside the defined model
(5.2.4.2.2) and thus invoking undefined behaviour (3.4.3). But you
AREN'T for isnan(), because its specification is to test for a NaN.
I also mentioned the FLT_EVAL_METHOD, which conflicts with much else
in the standard (including the IEEE 754 support). Which overrides which?
And there's more.
You are correct that an implementation may specify its behavior so that
they are equivalent, but that is NOT what you originally said, which
was:
What I meant is that isnan() and x != x can be seen as equivalent
even if __STDC_IEC_559__ is 1.
A programmer or source-to-source preprocessor should NOT regard them
as equivalent, and there is not even a request that a compiler writer
should do so.
This area is a disaster on wheels.
Regards,
Nick Maclaren.