How Are Unlimited Precision Integers Accomplished?

Uncle_Alias zephinilium at yahoo.com
Thu May 23 20:01:52 EDT 2002


Paul Rubin <phr-n2002a at nightsong.com> wrote in message news:<7xbsb7zrlc.fsf at ruckus.brouhaha.com>...
> 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.

That explains part of my surprise: I'd been using an earlier version
on the Mac, and am now using 2.2.1 on the PC.

So what fun things can we do with this? Anyone have an algorithm for
calculating pi?



More information about the Python-list mailing list