> Or with less obfuscation ...

> use constant MAXINT => ~0; Not true on my box..

DB<1> print ~0 4294967295 DB<2> print ~0+1 4294967296 DB<3> print ~0+2 4294967297 ... DB<12> print ~0*2**18 1.12589990658048e+15 ... DB<15> print ~0*2**17 562949953290240 ... DB<33> p unpack('J', pack('j', -1)); 4294967295 DB<34> p 0+sprintf('%u', -1); 4294967295
The MAX_INT is somewhere between 2**49 and 2**50!

UPDATE:

DB<81> p 999999999999999+1 1e+15 DB<82> p 999999999999998+1 999999999999999 DB<83> p 999999999999998+2 1e+15 DB<84> p 999999999999998+2-1 999999999999999 DB<85> p 1e+15-1 999999999999999
Seems to depend on the decimal representation of the mantissa of the floating point arithmetics.

UPDATE:

to be more precise, integers still work internally for higher numbers even if they can't be represented.

DB<88> p 999999999999998+4-5 999999999999997 ... DB<96> p 999999999999999+2**52 -2**52 999999999999999 DB<97> p 999999999999999+2**53 -2**53 1e+15

UPDATE

Last but not least
DB<32> $x=0;for(1..2**31) {print;last if $x++>5} Range iterator outside integer range at (eval 36)[/usr/share/perl/5.10 +/perl5db.pl:638] line 2. DB<33> $x=0;for(1..2**30) {print;last if $x++>5} 1234567 DB<34> $x=0;for(1..~0) {print;last if $x++>5} Range iterator outside integer range at (eval 45)[/usr/share/perl/5.10 +/perl5db.pl:638] line 2.
The range operator seems only to be implemented for signed 32bits integers...so MAX_INT wouldn't even help here!
DB<46> $x=0;for(1..2**31-2) {print;last if $x++>5} 1234567 DB<47> $x=0;for(1..2**31-1) {print;last if $x++>5} Range iterator outside integer range at (eval 51)[/usr/share/perl/5.10 +/perl5db.pl:638] line 2.

Cheers Rolf


In reply to Re^3: Infinity and Inf? (MAX_INT) by LanX
in thread Infinity and Inf? by LanX

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.