Keep It Simple, Stupid PerlMonks

### Infinity recognized as number

by fglock (Vicar)
 on Nov 22, 2002 at 16:48 UTC 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.

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.

-Nitrox

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 (Canon) 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.

Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://215169]
Approved by Mr. Muskrat
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2023-09-30 03:43 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?

No recent polls found

Notices?