Boost logo

Boost :

From: Guillaume Melquiond (guillaume.melquiond_at_[hidden])
Date: 2005-12-01 12:19:32


Le jeudi 01 décembre 2005 à 16:49 +0000, John Maddock a écrit :
> However, an interesting property of NaN's is that:
>
> if x is a NaN then:
>
> x == x
>
> is *false* under IEEE arithmetic rules, so you can't actually tell whether
> you've got the same NaN back or not anyway!
>
> The only thing you can tell is the sign of the NaN: according to C99 you can
> get the sign of a NaN from signbit, and set the sign of a NaN with copysign,
> but there's no way to portably implement those two :-(

The sign is actually the one information of a NaN you don't want to get
back. The IEEE-754 standard explicitly mandates that NaN do not have a
sign (or more precisely, the sign of a NaN is not part of its payload).

All the other bits of a NaN value are important however. They are its
payload and are supposed to be stable through arithmetic operations
(except when an operation involves two NaNs). As a matter of fact, NaNs
were conceived to carry information (debug information mainly).

At a time, there even were discussions on revising the IEEE-754 standard
to describe a syntax like NaN0x3ff800. This proposal was withdrawn
because it was so high-level, but it should give an idea on what NaNs
were about.

Best regards,

Guillaume

PS: because of poor implementations of this part of the standard, NaN
payloads were never widely used. So my mail is only here to clear some
misconceptions on NaNs, not to influence in any way how they should be
handled.


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk