Boost logo

Boost :

From: John Maddock (john_at_[hidden])
Date: 2006-07-25 08:26:54


Martin Bonner wrote:
> ----Original Message----
> From: Johan Råde
>
>> template<class T> bool is_nan(T a)
>> {
>> return a != a;
>> }
>>
>>
>> 1. Do these implementations work an all platforms?
>
> I believe is_nan is vunerable to over-eager optimizers for built-in
> types.

If implemented that way, then yes: only compilers in strict IEEE mode and
probably with optimisations turned off will do the right thing. It won't
work at all on platforms with non-IEEE arithmetic :-(

Which I why I routed everything through fpclassify: try get it right once in
one place and hopefully it doesn't turn into a maintenence problem :-)

Of course if the platform has native floating point classification macros
then these should be used: they're likely to be much more efficient than
"generic" solutions. Unfortunately I found several platforms with native
macros that didn't actually do the right thing in all cases during testing
of that code :-(

John.


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