long number multiplication

  • Thread starter I.V. Aprameya Rao
  • Start date
I

I.V. Aprameya Rao

hi

i have been wondering, how does python store its very long integers and
perform aritmetic on it.

i needed to implement this myself and was thinking of storing the digits
of an integer in a list.

however this would be very slow for operations like division etc.

so if anyone can point me to some links or some method on how to do this i
would appreciate it

aprameya rao
 
N

Nick Coghlan

I.V. Aprameya Rao said:
hi

i have been wondering, how does python store its very long integers and
perform aritmetic on it.

i needed to implement this myself and was thinking of storing the digits
of an integer in a list.

however this would be very slow for operations like division etc.

so if anyone can point me to some links or some method on how to do this i
would appreciate it

aprameya rao

I don't know of any design docs, but the source itself is easily available:
http://cvs.sourceforge.net/viewcvs....rc/Objects/longobject.c?rev=1.165&view=markup

Look at Python 2.4's decimal.py for something which is still pretty slow (heavy
number crunching in Python code just ain't pretty), but alleviates that somewhat
by using long objects to do the grunt work in most of the numerical operations.

(Random aside: actually having Decimal store long objects instead of a list of
digits slows it down. The arithmetic is faster, but the exponentiation +
division required for rounding is significantly slower than the list slicing
that the current implementation is able to use).

Cheers,
Nick.
 
J

Jeremy Bowers

i have been wondering, how does python store its very long integers and
perform aritmetic on it.

i needed to implement this myself and was thinking of storing the digits
of an integer in a list.

Uh, why? What possible environment are you programming in where the
correct answer isn't to grab one of many high-quality libraries to do it?

(Homework? If that's the case the Python source will likely prove too
complicated to be useful to you due to optimization, though I haven't read
it and I don't directly know.)
 
N

Nick Craig-Wood

I.V. Aprameya Rao said:
i have been wondering, how does python store its very long integers and
perform aritmetic on it.

i needed to implement this myself and was thinking of storing the digits
of an integer in a list.

however this would be very slow for operations like division etc.

so if anyone can point me to some links or some method on how to do this i
would appreciate it

Anyone interested in this subject should read

SemiNumerical Algorithms D.E.Knuth, Addison-Wesley

Its the bible for this area of computer science! Its also rather big
and expensive so you'll probably want to look at in the library...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,766
Messages
2,569,569
Members
45,045
Latest member
DRCM

Latest Threads

Top