On Sun, Aug 07, 2005 at 11:03:08AM -0700, Yitzchak Scott-Thoennes wrote:
> On Mon, Jul 25, 2005 at 05:27:36PM -0700, Sisyphus wrote:
> > use warnings;
> > 
> > my $z = NaN;
> > 
> > $z += 1;
> > 
> > print $z, "\n";
> > 
> > __END__
> > 
> > When I run that I get an output of simply:
> > 1
> > 
> > NaN + 1 should be NaN, not 1. If NaN is treated as a string, then
> > you would expect a value of 1 - but if NaN were being treated as
> > a string there would have been a warning that "NaN" is not numeric -
> > and no such warning appears. One is left to conclude that NaN is
> > understood, but not handled correctly. Inf is similarly mishandled.
> 
> My impression is that we lost nan/inf handling when we switched away
> from using the libc atof.  This (as yet untested) should help some,
> if we want to go this route:
> 
> --- perl/numeric.c.orig 2005-06-07 10:30:19.000000000 -0700
> +++ perl/numeric.c      2005-08-07 10:23:55.574304000 -0700
> @@ -893,6 +893,21 @@
>             ++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 */
>  
> 
> > Same problem on both Linux and Win32.
> > 
> > There has been some discussion about this on the c.l.p.misc thread
> > called "IEEE NaN screwed up?" and the p5p thread "NaN on platforms
> > that don't support it".
> > 
> > Seems that the perlop, perlfunc, and perldata docs are also in need
> > of change wrt what they say about NaN.
> 
> They need to not encourage barewords, at least.

"Fixing" that part:

--- perl/pod/perlop.pod.orig    2005-07-18 02:22:07.000000000 -0700
+++ perl/pod/perlop.pod 2005-08-10 22:51:33.017411200 -0700
@@ -369,8 +369,8 @@
 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.

Reply via email to