Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^4: nans, infs, and vomit

by syphilis (Bishop)
on Sep 02, 2008 at 01:05 UTC ( #708362=note: print w/replies, xml ) Need Help??


in reply to Re^3: nans, infs, and vomit
in thread nans, infs, and vomit

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

Replies are listed 'Best First'.
Re^5: nans, infs, and vomit
by ysth (Canon) on Sep 02, 2008 at 03:27 UTC
      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
        Try this instead:
        $ perl -wle'print "infantile paralysis" + 0' Argument "infantile paralysis" isn't numeric in addition (+) at -e lin +e 1. inf
        or even:
        $ perl -le'use warnings "FATAL"=>"numeric"; print "infantile paralysis +" + 0'
        I guess I'd like to know more about where you are finding this problematic. I don't quite get why you'd be taking arbitrary strings and numericizing them.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://708362]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2019-12-15 12:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?