How Are Unlimited Precision Integers Accomplished?
Martin v. Loewis
martin at v.loewis.de
Fri May 24 17:02:01 EDT 2002
Michael Chermside <mcherm at destiny.com> writes:
> 2**( 15 * (2**MAXINT) ) - 1
[...]
> >>> big = 1L << (2**31 - 1)
> >>> big <<= 15
> >>> big += 1
> >>> big <<= 45
> >>>
>
> As you can see, it should have overflowed (I thought) in line 3.
I really cannot see why that should overflow. Performing
big = 1L << (2**31 - 1)
big <<= 15
is the same as performing
big = 1L << (2**31 + 14)
which is roughly
2**(15 * (2**27))
So this is *much* less than 2**( 15 * (2**MAXINT) ) - 1.
On any 32-bit machine, the memory needed to store the largest large
integer exceeeds the amount of memory that the processor can
address. For a 64-bit machine, the same is true if MAXINT is 2**63-1.
Regards,
Martin
More information about the Python-list
mailing list