[Tutor] Re: large number question

Roel Schroeven rschroev_nospam_ml at fastmail.fm
Sun Sep 26 15:01:06 CEST 2004


Andrei wrote:

> Dick Moores wrote on Sat, 25 Sep 2004 21:08:14 -0700:
> 
>>I'm wondering if there's a way around the apparent limit on the size of 
>>integers. If I enter anything larger than about 4,610,000,000,000,000,000 
>>(4 quintillion, 610 quadrillion in American English), I get
>>"OverflowError: long int too large to convert to int"
> 
> The nice thing is that Python shows you *exactly* where the error occurs in
> a traceback, but you didn't provide that information. I think the xrange
> function doesn't like very large integers. I don't know where the limit of
> 4.6e18 comes from though. For me it refuses to work from 2**31 onward
> (2.15e9), which is basically what you'd expect on a 32-bit system. 

That's easy: the 4.6e18 is not the input to xrange; xrange sees the 
square root of that (plus one to be precise), which happens to be 
relatively close to 2**31:

 >>> 4.6e18**.5 + 1
2144761059.9527216
 >>> 2**31
2147483648L
 >>> (4.6e18**.5+1)/2**31
0.99873219614509567

-- 
"Codito ergo sum"
Roel Schroeven



More information about the Tutor mailing list