473,698 Members | 2,737 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

long number multiplication

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

Jul 18 '05 #1
3 2044
I.V. Aprameya Rao wrote:
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.p...65&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.
Jul 18 '05 #2
On Sun, 05 Dec 2004 09:02:18 +0530, I.V. Aprameya Rao wrote:
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.)

Jul 18 '05 #3
I.V. Aprameya Rao <ap******@stude nts.iiit.net> wrote:
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...

--
Nick Craig-Wood <ni**@craig-wood.com> -- http://www.craig-wood.com/nick
Jul 18 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
9831
by: Alkomat | last post by:
Hy! I have a problem viewing long numbers in the Schema Browser. I only see 1,0000000000019E37 for example. How can i view the hole number? Thanks for your answer! Thomas
1
10491
by: FX | last post by:
Hi all, How can I get a random long number ? (nb: Random class allows me to generate only int number, I would like number possibly greater than int.MaxValue)
5
1443
by: junky_fellow | last post by:
Hi guys, I have some value stored in an unsigned long integer. My requirement is to zero the 13 LSB bits of this number. Or more specifically, I want to make the number 8k (8192) aligned. For instance, if the value is 26 kilobytes I should get 24kilobytes. Can somebody tell me a portable way of doing it. I thought of using a mask 0xfffe0000, but that won't work if long is 8 bytes long on
9
10878
by: helPlease | last post by:
hello !! Can anybody provide me an algorithm or C code for long integer multiplication.It's urgent.
18
1708
by: 66650755 | last post by:
I would like to enter a string such as "111111111111.....11111111" (50 ones),and then convert it to a number(111111111111.....11111111),because I want to use that number to do some additions.How can I do that? The following is my trial,but I find that the "a" is always 0. #include<stdio.h> #include<stdlib.h>
4
17408
by: ankitabhatia | last post by:
i have 2 long numbers eg xl=12345678 xr=87654321 i want to merge these 2 nos. into a single long number i have to do this in java.. any help would be great..thanks a lot:)
3
2731
by: jatinch | last post by:
i am implementing blowfish algorithm.. i have a long number or a 64 bit no. say X i have to divide this 64 bit block into two 32 bit blocks say xl and xr. after doing some calculations i have to convert these two 32 bit blocks into 64 bit block again.. so how do i do this pls help..
0
8683
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8610
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9031
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8902
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8873
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
4623
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3052
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2339
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2007
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.