How Are Unlimited Precision Integers Accomplished?

Tim Peters tim.one at comcast.net
Thu May 23 10:32:02 EDT 2002


[Martin v. Loewis]
> Of course, you can't use processor instructions for operations on
> these numbers (directly), so Python implements its own +, -, *, /,
> etc.

[Michael Chermside]
> For those of whose interest was piqued by this question, can someone
> elaborate with a simple summary of the data structure that is used,

See include/longintrepr.h

> the algorithms for performing the operations,

See objects/longobject.c, or read Knuth vol 2.  Only division and
exponentiation are non-obvious.

> and what senarios these are optimized for?

Correctness, portability, and generated code size, not for speed (e.g., use
GMP if you want peak speed, along with a history of "interesting" platform
bugs <wink>).






More information about the Python-list mailing list