How Are Unlimited Precision Integers Accomplished?

A.M. Kuchling akuchlin at ute.mems-exchange.org
Fri May 24 14:15:35 EDT 2002


In article <mailman.1022260069.18263.python-list at python.org>,
	Michael Chermside wrote:
> >>> big = 1L << (2**31 - 1)
> >>> big <<= 15
> >>> big += 1
> >>> big <<= 45

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
>>> 

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

--amk



More information about the Python-list mailing list