The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » sci.math.* » sci.math

Topic: High-precision Algorithm
Replies: 2   Last Post: May 12, 2013 5:39 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
James Waldby

Posts: 506
Registered: 1/27/11
Re: High-precision Algorithm
Posted: May 12, 2013 10:48 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

On Sat, 11 May 2013 15:00:17 -0700, KBH wrote:

>> Does anyone know of a function or software I can use (preferably in Visual Basic, but will use any algorithm) to perform high-precision math calculations, such as ...
> 'Thousand Digit Op' will multiply with two integer numbers that are 1000 digits or less and will divide with two integer numbers that are 2000 digits or less. Then it's possible to work with decimal point numbers by dropping the decimal points and keeping track of where the decimal point should be in the result.
> The application uses a small amount of instruction in the loops and then a large number of fast loops.
> Otherwise, I'm not familar with any open source libraries but there is a shareware UBasic available
> .

Perhaps you (KBH) could provide some timings and cross-checks of
'Thousand Digit Op' relative to Python's built-in large-number
arithmetic. Here is an example of timing some operations, within
the ipython interpreter, which is freely downloadable. Note, in
following, all of u, v/u, and v%u are about 500 digits long, while
v is about 1000 digits long. Python took about 20 microseconds
for v/u + v%u.

In [27]: u=3**1048

In [28]: v=5**1431

In [29]: v/u
Out[29]: 159588377228959077124033529846706173377670651019402817413903057980687239665812136895146535461691029393717561194039581042112941167384541312962207141090513753598883354972311476786828567327334557067321195729425873950404649780805993015698785979878971124960712319102981518907826172440288055238618916259743493881382859749952565937542160268965170299634066918779414688423865579464673280918269958244076237834716962819697213949665224639312089807278692420046672759354745098154816407376723302684184662808947654510L

In [30]: v%u
Out[30]: 103326703166979322767585007603325329851383449999195202897493052907961790225869481331767933862961846823885955634647416122394634047149232900536158317485041583325170788355276467455783992346226027047434201755968044448049463697686029887794902906939322808951006983461531977363098808187922066499128461713493537423899150272154451941901015773931881852167807937748056339937566567332680579077984997740268640971147835374932842977963626399422285827509371192145408304567650688258964404464654299922273397388585470015L

In [31]: w = v/u + v%u; print w

In [32]: %timeit w = v/u + v%u
10000 loops, best of 3: 19.3 us per loop


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.