long number multiplication

Michael Hudson mwh at python.net
Mon Dec 6 10:02:47 EST 2004


"Terry Reedy" <tjreedy at udel.edu> writes:

> "I.V. Aprameya Rao" <aprameya at students.iiit.net> wrote in message 
> news:Pine.LNX.4.44.0412050900300.12327-100000 at localhost...
> > i have been wondering, how does python store its very long integers and
> > perform aritmetic on it.

Well, up until fair recently it used "high school" arithmetic in base
2**15.  Now it uses Karatsuba multiplication and some very mild tricks
for exponentiation, I believe.

> The only real documention for stuff like this, other than random posts on 
> c.l.p., is the source code itself.  It is generally pretty readable.

Unfortunately, longobject.c is not one of the most readable bits :-(
It's not too bad, but it's no work of art.

Cheers,
mwh

-- 
  <etrepum> Jokes around here tend to get followed by implementations.
                                                -- from Twisted.Quotes



More information about the Python-list mailing list