Arbitrary precision calculations

Click For Summary
SUMMARY

The forum discussion centers on optimizing arbitrary precision calculations, specifically addressing the challenges of division in such calculations. Users report that while multiplication of large numbers (up to a thousand digits) is efficient, division to 250 decimal places is significantly slower, taking around 20 seconds. The discussion suggests using the Apfloat library for arbitrary precision arithmetic and proposes an iterative algorithm for division that involves estimating the inverse and refining the result through multiplication. The method involves starting with a 16-bit estimate and doubling precision with each iteration, which can improve performance.

PREREQUISITES
  • Understanding of arbitrary precision arithmetic
  • Familiarity with the Apfloat library for arbitrary precision calculations
  • Knowledge of iterative algorithms for numerical methods
  • Basic programming skills in VB2010 or similar languages
NEXT STEPS
  • Explore the Apfloat library documentation for implementation details
  • Research iterative algorithms for division in arbitrary precision, focusing on the method z = z (2 - x z)
  • Investigate the XNUMBERS package for VB-based arbitrary precision solutions
  • Learn about Fourier transforms and their application in optimizing arbitrary precision calculations
USEFUL FOR

Software developers, mathematicians, and anyone involved in high-precision computing or numerical analysis, particularly those working with large number calculations in programming environments like VB2010.

QuantumHop
Messages
68
Reaction score
0
I decided to write an arbitrary precision calculator but I'm having problems with division.

It will multiply a thousand digit number by another thousand digit number in about a second but to get a division result to about 250 decimal places is taking around 20 seconds, I cannot figure out how it should be done.

Anybody have any ideas?
 
Technology news on Phys.org
The optimizing algorithms for arbitrary precision can get complex, involving a combination of Fourier transforms and modulo (finite field) math. Apfloat (do a web search) is a package that you can get for free and includes source and some documentation on the algorithms. I'm not sure if division is done directly or if it's better to calculate the inverse (1/x) then multiply.
 
Last edited:
rcgldr said:
I'm not sure if division is done directly or if it's better to calculate the inverse (1/x) then multiply.
This is exactly the method I have used, it works but its very slow and the time taken to calculate the next decimal place increases exponentially. I was hoping there was some clever trick that would solve the problem, I've searched for solutions but haven't found one I can use in VB2010. ( yeah I know , learn a real language :biggrin: )
 
rcgldr said:
I'm not sure if division is done directly or if it's better to calculate the inverse (1/x) then multiply.

QuantumHop said:
I was hoping there was some clever trick that would solve the problem.
If you have a relatively fast multiply you can try this algorithm that converges to the result quadratically:

z ~= 1/x (use actual division for initial 16 bit estimate of 1/x).

then iterate this process using extended multiply algorithm.

z = z (2 - x z)

If you start off with a 16 bit estimated quotient, then the precision doubles to 32 bits after 1st step, 64 bits after second step, ... So if you need 64 bits, you would iterate twice, then do a test multiply t = x z, and adjust z +/- 1 bit for the final correction.
 

Similar threads

  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
857
  • · Replies 4 ·
Replies
4
Views
3K
Replies
4
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
Replies
3
Views
2K
  • · Replies 6 ·
Replies
6
Views
2K
  • · Replies 4 ·
Replies
4
Views
2K
  • · Replies 12 ·
Replies
12
Views
2K