How Are Unlimited Precision Integers Accomplished?

Paul Rubin phr-n2002a at nightsong.com
Wed May 22 19:32:31 EDT 2002


zephinilium at yahoo.com (Uncle_Alias) writes:
> I was playing around with computing powers of 2 the other night, and
> was watching Python spit out numbers. When I tested the output by
> dividing it by 2 repeatedly, it seemed to be accurate and not a
> rounded out number. This is amazing to me that it can calculate
> integers to unlimited precision. How is this done? (Please keep the
> explanation simple, for I am a mere amateur coder).

Yes, Python has a "long" (arbitrary precision integer) type whose size
is limited only by the amount of memory available.  Python version 2.2
uses longs when regular integer calculations overflow.  Earlier
versions of python will signal an integer overflow error if an
integer (normally 32 bits) gets too large.  That will happen
if you enter an exponent >= 31.




More information about the Python-list mailing list