How Are Unlimited Precision Integers Accomplished?

Michael Chermside mcherm at destiny.com
Fri May 24 15:00:32 EDT 2002


A.M. Kuchling writes:
> To really break things, I think this should really be something like:
> 
>>>> exp = 2**31L - 1
>>>> exp
> 2147483647L
>>>> exp = exp * 15
>>>> exp
> 32212254705L
>>>> 1 << exp
> Traceback (most recent call last):
>   File "<stdin>", line 1, in ?
> OverflowError: long int too large to convert to int

Yes, but that's just because << is defined to take only an int on the 
right-hand-side, not a number. It's not a limit to the size of a Long.

> Also note that Python can't print the value of your 'big' variable; it
> gets a MemoryError.

Yes, I noticed that. But I can still do arithmatic with it.

Now it's no big deal if Longs are actually limited to some absurdly big 
value rather than being of truely unlimited size so long as you are 
running on a machine with infinite memory. But what I don't get is why 
they AREN'T limited (or appear not to be) given the way they are coded.

-- Michael Chermside







More information about the Python-list mailing list