Re: Question on performance
On 2010-10-18 15:27:35 +0100, N.M. Maclaren wrote:
> 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 former is undefined behavior if you provide an argument that is
not supported by the implementation, e.g. an argument that would have
the encoding of a qNaN (from the user point of view) while the
implementation doesn't support NaN data, i.e. for the implementation
NaN doesn't exist.
Actually the behavior is undefined even before isnan is called: as
soon as the implementation handles some result that isn't a valid
value, the behavior is undefined.
> 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.
No, read above.
> I also mentioned the FLT_EVAL_METHOD, which conflicts with much else
> in the standard (including the IEEE 754 support). Which overrides which?
There as been some discussions about that in comp.std.c IIRC.
IMHO, the value of FLT_EVAL_METHOD must be consistent with the
real behavior.
> 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,
Why not?
--
Vincent Lefèvre <vincent@xxxxxxxxxx> - Web: <http://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <http://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / Arénaire project (LIP, ENS-Lyon)