On Tue, 27 Jan 2009, Nicholas Clark wrote:

> On Tue, Jan 27, 2009 at 10:24:46AM -0800, parti...@cvs.perl.org wrote:
> 
> > +                            else if (thefloat != thefloat) {
> 
> The above is the valid test for a NaN.
> 
> Note, Intel chose that the default optimiser setting on their compiler should
> be buggy. (Advice from Klortho #11912). The perl 5 Linux hints file suggests
> that one needs to add -we147 to enable correct floating point behaviour.
> 
> The best test that I'm aware of for "is it NaN or Inf?" is val != val * 0;
> Then, NaN is val != val, +Inf is val > 0, -Inf is val < 0;

Well, if they are available, isnan() and isinf() are probably worth 
trying.  You can piggy back on perl 5's $Config{d_isnan} and 
$Config{d_isinf}.  To distinguish +NaN from -NaN, I suspect you might also 
want to use signbit()  (which, alas, perl 5 doesn't probe for).

Some of these functions might only be available under certain compiler 
options or with certain extra libraries, depending on how a particular 
system attempts to adhere to different standards, but it's probably worth 
trying them.

-- 
    Andy Dougherty              dough...@lafayette.edu

Reply via email to