|
Boost : |
From: Johan Råde (rade_at_[hidden])
Date: 2006-07-25 08:44:25
John Maddock wrote:
> 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.
>
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>
John,
You seem to have thought through these issues carefully.
When will you submit the floating point properties library to Boost?
I need it.
Based on your document and input from Paul Giaconne
I suggest the following interface:
bool is_finite();
bool is_normal();
bool is_subnormal();
bool is_infinite();
bool is_plus_infinity();
bool is_minus_infinity();
bool is_nan();
bool is_quiet_nan();
bool is_signalling_nan();
The IEEE754 standard uses the term "denormal",
but the draft for the next revision of the IEEE754 standard uses the
term "subnormal", so "subnormal" is probably better.
--Johan Råde
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk