How Are Unlimited Precision Integers Accomplished?
Martin v. Loewis
martin at v.loewis.de
Thu May 23 03:09:42 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?
It uses more memory for larger numbers. A single byte can represent
256 values, two bytes 65536, three bytes 16777216, etc. So the internal
representation roughly has the number of bytes of the integer, and the
bytes themselves.
Of course, you can't use processor instructions for operations on
these numbers (directly), so Python implements its own +, -, *, /,
etc.
Regards,
Martin
More information about the Python-list
mailing list