develooper Front page | perl.perl5.porters | Postings from January 2005

Re: [perl #33106] perl does not warn if the argument eq "NaN"

From:
Yitzchak Scott-Thoennes
Date:
January 6, 2005 11:34
Subject:
Re: [perl #33106] perl does not warn if the argument eq "NaN"
Message ID:
20050106193442.GB1300@efn.org
On Sun, Dec 19, 2004 at 03:01:19PM -0800, Yitzchak Scott-Thoennes <sthoenna@efn.org> wrote:
> On Sun, Dec 19, 2004 at 03:22:54PM -0500, John Peacock <jpeacock@rowman.com> wrote:
> >  Binary "<=>" returns -1, 0, or 1 depending on whether the left
> >  argument is numerically less than, equal to, or greater than the right
> >  argument.  If your platform supports NaNs (not-a-numbers) as numeric
> > -values, using them with "<=>" (or any other numeric comparison)
> > -returns undef.
> > +values, using them with "<=>" returns undef.  NaN is not "<", "==", ">",
> > +"<=" or ">=" anything (even NaN), so those 5 return false. NaN != NaN
> > +returns true, as does NaN != anything else. If your platform doesn't
> > +support NaNs then NaN is just a string with numeric value 0.
> > +
> > +    perl -le '$a = NaN; print "No NaN support here" if $a == $a'
> > +    perl -le '$a = NaN; print "NaN support here" if $a != $a'
> 
> Unfortunately it seems the part to suppress numeric warnings for
> inf/nan-looking strings is there, but not the part to actually make
> them be non-zero numbers.  Don't know if this was always the case, or
> if the code to make the above snippet work was once present but now
> broken.

Aha!  In 5.6.x, perl uses the libc atof/strtold/atofl to parse numbers;
at some point in 5.8.x it was changed to use a replacement in numeric.c
(unless on Unicos or configured with -Accflags=-DUSE_PERL_ATOF=0).

And the numeric.c atof doesn't support nan/inf.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About