Arbitrary precision calculations

In summary: There is an algorithm that converges to the result quadratically. All you need to do is z ~= 1/x (use actual division for initial 16 bit estimate of 1/x). Then iterate this process using extended multiply algorithm.
  • #1
QuantumHop
68
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
  • #2
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:
  • #3
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: )
 
  • #4
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.
 
  • #5

FAQ: Arbitrary precision calculations

1. What are "Arbitrary precision calculations"?

"Arbitrary precision calculations" refer to a type of mathematical calculation that allows for a higher degree of precision than traditional calculations. It involves using algorithms and software to perform calculations with an unlimited number of digits, instead of the limited number of digits used in traditional calculations.

2. Why are "Arbitrary precision calculations" important in scientific research?

Arbitrary precision calculations are important in scientific research because they allow for more accurate and precise results. In many scientific fields, even small errors in calculations can have a significant impact on the overall results. Using arbitrary precision calculations can help to reduce these errors and provide more reliable data.

3. What are the limitations of "Arbitrary precision calculations"?

While arbitrary precision calculations can provide a higher degree of precision, there are still limitations. These calculations can be computationally intensive and may require more time and resources to perform. Additionally, there may still be rounding errors or other sources of error that can affect the accuracy of the results.

4. How are "Arbitrary precision calculations" used in different fields of science?

Arbitrary precision calculations are used in a variety of fields in science, including physics, chemistry, and biology. They are particularly useful in fields that involve complex equations or measurements that require a high level of precision, such as in quantum mechanics or molecular dynamics simulations.

5. Are there any alternatives to "Arbitrary precision calculations"?

Yes, there are alternatives to arbitrary precision calculations, such as using specialized hardware or software that can perform calculations with a higher degree of precision. Additionally, some scientists may use statistical methods or other approaches to account for potential errors in traditional calculations.

Similar threads

Replies
1
Views
1K
Replies
4
Views
2K
Replies
6
Views
1K
Replies
6
Views
751
Replies
12
Views
2K
Replies
15
Views
8K
Replies
4
Views
1K
Back
Top