in reply to Re^2: Infinity and Inf?
in thread Infinity and Inf?
> use constant MAXINT => ~0; Not true on my box..
The MAX_INT is somewhere between 2**49 and 2**50!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
UPDATE:
Seems to depend on the decimal representation of the mantissa of the floating point arithmetics.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
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 leastThe range operator seems only to be implemented for signed 32bits integers...so MAX_INT wouldn't even help here!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.
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Infinity and Inf? (MAX_INT)
by ikegami (Patriarch) on Sep 01, 2010 at 15:51 UTC | |
by LanX (Saint) on Sep 01, 2010 at 16:36 UTC | |
by ikegami (Patriarch) on Sep 01, 2010 at 19:16 UTC | |
|
Re^4: Infinity and Inf? (MAX_INT)
by BrowserUk (Patriarch) on Sep 01, 2010 at 14:53 UTC | |
by ikegami (Patriarch) on Sep 01, 2010 at 16:08 UTC | |
by LanX (Saint) on Sep 01, 2010 at 15:09 UTC | |
by BrowserUk (Patriarch) on Sep 01, 2010 at 16:42 UTC | |
by LanX (Saint) on Sep 01, 2010 at 17:12 UTC | |
by ikegami (Patriarch) on Sep 01, 2010 at 20:07 UTC | |
by BrowserUk (Patriarch) on Sep 01, 2010 at 17:22 UTC | |
|
Re^4: Infinity and Inf? (MAX_INT)
by BrowserUk (Patriarch) on Sep 01, 2010 at 13:16 UTC | |
by LanX (Saint) on Sep 01, 2010 at 13:27 UTC | |
by tye (Sage) on Sep 01, 2010 at 13:53 UTC | |
by LanX (Saint) on Sep 01, 2010 at 14:29 UTC |