# looking for quick method to calculate pi

Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last
• 07-14-2006
MindlessXD
looking for quick method to calculate pi
I'm looking for a FAST way to calculate X digits of pi in hexadecimal without using any external libraries (i.e. APFloat, etc.).

Currently I've found code for extracting any specific digit of pi in hexadecimal (using the BBP formula, I believe), but using this code to compute even 1000 digits of pi is SLOW.

• 07-14-2006
VirtualAce
I wonder why.
• 07-14-2006
MindlessXD
You're going to have to keep wondering, because it's not homework. (I assume that's what you're thinking, anyway.)
• 07-14-2006
whiteflags
> using this code to compute even 1000 digits of pi is SLOW.
Well pi is an extremely long real number that has no documented repetitions for about 50 billion places, if I remember correctly. Few of us are mathematicians; I would be happy with what is already possible through the work of someone else.
• 07-15-2006
Mario F.
As Citizen said.

There was this mathematician that took 15 years to calculate manually the first 1000 digits, if I recall correctly. He pusblished the results and died peacefully, and an acomplished man, in his bed (for his own sake, I hope not alone), only to be found later on he made a mistake somewhere halfway. And all numbers that followed were wrong.

Anyways... You can use the Machin's Formula
• 07-15-2006
CornedBee
You could also go to one of the countless sites that show PI at a high precision, copy that into a file, and read the file.
• 07-15-2006
MindlessXD
would it be faster or easier to calculate the square root of 2 to X hexadecimal digits?
• 07-15-2006
whiteflags
A close approximation of pi is the quotient of 22 / 7. You may have an easier time converting that to hexidecimal.
• 07-16-2006
anon
Quote:

Originally Posted by citizen
A close approximation of pi is the quotient of 22 / 7. You may have an easier time converting that to hexidecimal.

No,
pi = 3.141592...
22/7 = 3.142857...

As you can see the approximation is not very close, although in practice this kind of precision would be enough in most cases.

I know there's a method to calculate the n-th hex digit of pi (I think even not knowing about the other heximal places) and you could google for that. Probably, you could correctly calculate pi to any digit in a loop.

It was too advanced mathematics for me to understand...
• 07-16-2006
twomers
• 07-17-2006
Micko
Here's how I calculate pi:
Code:

`double x = 4 * atan( 1.0 );`
• 07-17-2006
DougDbug
Quote:

Originally Posted by Micko
Here's how I calculate pi:
Code:

`double x = 4 * atan( 1.0 );`

A fine technique, as long as you understand and accept the limitations of atan(). ;)
• 07-17-2006
MindlessXD
The problem is that want the *digits* of pi (or the sqrt of 2), not the value.
• 07-17-2006
laserlight
Once you have the value you can get the digits, but yes, I think reading pre-calculated values from file may be easier.
• 07-17-2006
anon
Enjoy: pi digits
Seems correct to me.
Show 80 post(s) from this thread on one page
Page 1 of 2 12 Last