http://www.perl.com/doc/FMTEYEWTK/is_numeric.html
Yes - that puts this behaviour into context. When any string is put into numeric context, perl just hands that string over to the underlying C implementation of atof(), and we're then at the mercy of what that function does with the string it has been passed.
On some systems, atof turns the strings 'nan' and 'inf' into actual nans and infinities. On other implementations of atof,a nan/inf will never result from a call to atof - irrespective of what string it receives. This is not a very convenient situation ... but we can't blame perl for differences in the underlying C libraries.
Thanks for the link Anonymous Monk.
Cheers, Rob | [reply] [d/l] [select] |
Perl stopped using atof (which is shorthand for strtod(str, (char **)NULL)) when C99 decided that should start interpreting "0x1" as 1 instead of 0 (see http://www.opengroup.org/onlinepubs/009695399/functions/strtod.html#tag_03_740_07 "The changes to strtod() introduced by the ISO/IEC 9899:1999 standard can alter the behavior of well-formed
applications complying with the ISO/IEC 9899:1990 standard...")
| [reply] [d/l] |
Perl stopped using atof ...
Oh ... thanks for the correction.
It all still looks pretty weird to me on linux:
$ perl -le 'print "infantile paralysis" + 0'
inf
$ perl -le 'print "nanny goat" + 0'
nan
I feel no strong desire to port that type of behaviour to non-POSIX platforms :-)
Cheers, Rob | [reply] [d/l] |