arithmetic in longobject.c

Tim Peters tim_one at email.msn.com
Wed Apr 26 23:12:14 EDT 2000


[posted & mailed]

[Peter Schneider-Kamp]
> I got a few questions about longobject.c which a quick
> glance at the source could not answer.
>
> What algorithms does longobject.c implement for
> multiplication and division of long integers?

Knuth's.

> What representation is used for long integers?

See the comment block near the top of Include/longintrepr.h (signed
magnitude, base 2**15, using only 15 of each 16 bits -- or however long a C
short happens to be on your platform).

> I'd like to add a rns representation option in python
> for speedups in multiplication.  Internal knowledge
> of the long integer arithmetic would be helpful
> to make the right design choices.

Unless you're just having fun, read about the mpz module in the Library
Reference Manual (which allows use of GMP from within Python).  "Optimized"
bigint arithmetic is unlikely to get into the Python core.

too-little-demand-for-so-much-hairy-code-ly y'rs  - tim






More information about the Python-list mailing list