Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

nans, infs, and vomit

by syphilis (Bishop)
on Sep 01, 2008 at 13:00 UTC ( #708203=perlquestion: print w/replies, xml ) Need Help??

syphilis has asked for the wisdom of the Perl Monks concerning the following question:

Hi,
With perl 5.10 (and no doubt earlier) on linux, the string 'nan', when used in a numeric context, actually becomes a nan ... and the string 'inf', when used in a numeric context, actually becomes an infinity.

I understand it has something to do with the underlying libc, but I'm also wondering what the underlying rationale is (if there *is* any). Is there, eg, some IEEE standard that encourages this nauseating behaviour ?

Afaict on Win32, there's no string (PV) that, when used in numeric context, will be treated as either a nan or an infinity ... and, to my way of thinking, that's exactly as it should be. For once windows gets it right and ignores the "Ooooh, wouldn't it be groovy to have strings that become nans/infinities when used numerically" temptation.

But, then again, I've been wrong before and maybe there are good reasons that perl on linux decides to indulge in what are, to me, nothing more than gimmicks for the feeble-minded. That being the case, precisely what *are* those "good reasons" ?

Cheers,
Rob

Replies are listed 'Best First'.
Re: nans, infs, and vomit
by dHarry (Abbot) on Sep 01, 2008 at 13:41 UTC

    No IEEE rationale, the standard dealing with this stuff is IEEE 754 (and its revision IEEE 754r) but it only discusses things like the bit patterns for representing those values.

    I recently followed the discussion on your post How to create nan/inf with interest. In Perl 6 everything will be better, but when I read A Romp Through Infinity I was a bit puzzled/confused.

    In mathematics it is well defined but outside of math it seems to depend on the specific domain, i.e. you can find thousands of papers discussing infinity/NaN on IEEE. Enjoy:-)

    Cheers,
    dHarry

    Update:
    IEEE-754 References for the NaN/Inf inclined monk.

      No IEEE rationale

      In a nutshell then ... what is it that inspired this notion that the strings "nan"/"inf" should actually become nans/infs when used numerically ? Was it something that the perl porters dreamed up all by themselves ?

      It sure has been giving me some headaches lately. (Actually, it's the lack of uniformity across different operating systems that's the problem. If they all did the same thing, no matter how distasteful that "same thing" was, life would be much simpler :-)

      Cheers,
      Rob
Re: nans, infs, and vomit
by ysth (Canon) on Sep 02, 2008 at 02:52 UTC
    FWIW, this is my fault, to the extent that I fixed it after it had been broken for a very long time. And it was back in 5.8.8. The relevant IEEE standard would be here (one-time registration required).

    If you'd like to make it work on non-POSIX platforms, please do.

Re: nans, infs, and vomit
by Anonymous Monk on Sep 01, 2008 at 14:07 UTC
Re: nans, infs, and vomit
by Anonymous Monk on Sep 01, 2008 at 13:39 UTC
    I understand it has something to do with the underlying libc, but I'm also wondering what the underlying rationale is (if there *is* any). Is there, eg, some IEEE standard that encourages this nauseating behaviour ?
    http://en.wikipedia.org/wiki/NaN
      http://en.wikipedia.org/wiki/NaN

      Already been there ... couldn't spot anything relevant to nanification/infinication of strings. Did I miss something ?

      Cheers,
      Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://708203]
Approved by moritz
Front-paged by moritz
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (5)
As of 2019-11-17 22:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Strict and warnings: which comes first?



    Results (87 votes). Check out past polls.

    Notices?