From: Yitzchak Scott-Thoennes Date: Sun, 7 Aug 2005 20:03:00 +0000 (+0000) Subject: Re: [perl #36654] Inconsistent treatment of NaN X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2b54f59ff973752abae83d93b744e48e13815b05;p=p5sagit%2Fp5-mst-13.2.git Re: [perl #36654] Inconsistent treatment of NaN Date: Aug 7, 2005 8:03 PM Message-ID: <20050807180308.GA2112@efn.org> Subject: Re: [perl #36654] Inconsistent treatment of NaN From: Yitzchak Scott-Thoennes Date: Wed, 10 Aug 2005 22:53:51 -0700 Message-ID: <20050811055351.GA2296@efn.org> p4raw-id: //depot/perl@25299 --- diff --git a/numeric.c b/numeric.c index 3015842..5eafdda 100644 --- a/numeric.c +++ b/numeric.c @@ -893,6 +893,21 @@ Perl_my_atof2(pTHX_ const char* orig, NV* value) ++s; } + /* punt to strtod for NaN/Inf; if no support for it there, tough luck */ + +#ifdef HAS_STRTOD + if (*s == 'n' || *s == 'N' || *s == 'i' || *s == 'I') { + char *p = negative ? s-1 : s; + char *endp; + NV rslt; + rslt = strtod(p, &endp); + if (endp != p) { + *value = rslt; + return (char *)endp; + } + } +#endif + /* we accumulate digits into an integer; when this becomes too * large, we add the total to NV and start again */ diff --git a/pod/perlop.pod b/pod/perlop.pod index ba2ff9f..da7cef5 100644 --- a/pod/perlop.pod +++ b/pod/perlop.pod @@ -369,8 +369,8 @@ values, using them with "<=>" returns undef. NaN is not "<", "==", ">", 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' + perl -le '$a = "NaN"; print "No NaN support here" if $a == $a' + perl -le '$a = "NaN"; print "NaN support here" if $a != $a' Binary "eq" returns true if the left argument is stringwise equal to the right argument.