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

Infinity recognized as number

by fglock (Vicar)
on Nov 22, 2002 at 16:48 UTC ( #215169=perlquestion: print w/ replies, xml ) Need Help??
fglock has asked for the wisdom of the Perl Monks concerning the following question:

perldelta (5.6.1) says:

    Infinity is now recognized as a number.

I'd like to find out what it means, since it doesn't seem to work in Perl expressions like:

 print 1 + Infinity;   # prints "1"

I also tried "Inf", "inf", "infinity", but nothing seems to work.

Comment on Infinity recognized as number
Select or Download Code
Replies are listed 'Best First'.
Re: Infinity recognized as number
by Nitrox (Chaplain) on Nov 22, 2002 at 17:09 UTC
    Perl handles infinity as IEEE 754 standards, read more here.


Re: Infinity recognized as number
by crenz (Priest) on Nov 22, 2002 at 17:08 UTC
Re: Infinity recognized as number
by fglock (Vicar) on Nov 22, 2002 at 18:22 UTC

    Thanks all. The point is, Perl prints out the Infinity number as "Inf" (FreeBSD) or "inf" (linux). What I learned is that the string "Inf" is just a string.

    Now I'm using $inf=10**10**10

      FWIW, perl 5.16.1 :)
      $ perl -e " print 1 + Infinity " 1.#INF $ perl -e " print 1 + inf" 1.#INF $ perl -e " print int inf" 1.#INF $
Re: Infinity recognized as number
by Mr. Muskrat (Abbot) on Nov 22, 2002 at 17:03 UTC

    I don't know where all it comes into play but try this:

    #!/usr/bin/perl my $int = 999999999999999999999999999999999999; print $int**$int,$/;

    It outputs: 1.#Inf

Re: Infinity recognized as number
by shemp (Deacon) on Nov 22, 2002 at 18:08 UTC
    Nothing to do with infinify, rather a comment on perls numeric interpretation of scalars.
    using the addition operator "+", perl will use its numeric interpretation of both operands.
    1 evaluates to 1 (like you'd expect)
    "Infinity" evaluates to 0 ("zero")
    so the addition results in 1

    in general, when perl needs a numeric interpretation of a scalar, the value is the value of the maximal length numeric substring that starts at the first character of the scalar.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://215169]
Approved by Mr. Muskrat
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2015-10-13 23:34 GMT
Find Nodes?
    Voting Booth?

    Does Humor Belong in Programming?

    Results (317 votes), past polls