Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University 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: 358
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.
>
> http://www.kbhscape.com/integer.htm
>
> 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
262915080395938399891618537450031503229054101018598020311396110888649029891681618226914469324652876217603516828686997164507575214533774213498365458575555336924054143327587944242612559673560584114755397485393918398454113478492022903493688886818293933911719302564513496270924980628210121737747377973237031305282010022107017879443176042897052151801874856527471028361432146797353859996254955984344878805864798194630056927628851038734375634788063612192081063922395786413780811841377602606458060197533124525

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

--
jiw



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

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.