Arbitrary precision calculations

Click For Summary

Discussion Overview

The discussion revolves around the challenges of implementing division in an arbitrary precision calculator, particularly focusing on performance issues when calculating results to a high number of decimal places. Participants explore various algorithms and methods to optimize division operations compared to multiplication.

Discussion Character

  • Technical explanation
  • Debate/contested
  • Mathematical reasoning

Main Points Raised

  • One participant reports that their arbitrary precision calculator performs multiplication of large numbers quickly but struggles with division, taking significantly longer to compute results to 250 decimal places.
  • Another participant suggests that optimizing algorithms for arbitrary precision can be complex, mentioning the use of Fourier transforms and modulo math, and questions whether division should be done directly or by calculating the inverse first.
  • A participant confirms using the inverse method for division but notes that it is slow and the time to compute each additional decimal place increases exponentially, expressing a desire for a more efficient solution.
  • Another participant proposes an iterative algorithm that starts with an initial estimate for the inverse and doubles precision with each iteration, suggesting a method to improve the speed of convergence for division.
  • A suggestion is made to check out a VB-based arbitrary precision package called XNUMBERS, which may provide insights or solutions related to division.

Areas of Agreement / Disagreement

Participants express varying opinions on the best method for performing division in arbitrary precision calculations, with no consensus reached on a single optimal approach. Multiple competing views and methods are presented.

Contextual Notes

Participants mention specific algorithms and methods without providing complete details on their implementation, and there is an acknowledgment of the complexity involved in optimizing arbitrary precision division.

Who May Find This Useful

Individuals interested in arbitrary precision arithmetic, algorithm optimization, or those developing software for high-precision calculations may find this discussion relevant.

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
1K
  • · 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