# C for PI

• 04-28-2002
Lynux-Penguin
C for PI
I have been looking for a program to calculate pi to a digit given
all I have seen so far are
100 digits
1000 digits
and
1001 digits

why can't there be one to display PI to any amount of digits?

so I don't think it is possible for C basic C to compute pi.
In calculus the equation (at least, my way of getting the equation is right)

pi = 2 ( integral(sqrt(1-x^2)dx, from -1 to 1)

I derived this 2 years ago, I think there is also a series to do this but that is basically it right there.

If anyone finds a program to calculuate pi let me know. I would really appreciate it.
• 04-28-2002
Lynux-Penguin
update
the expanded version of the computation of pi is
arcsin(1)/2+x*sqrt(1-x^2)/2=PI/4
or
Code:

_____
arcsin(1)      1\/1-1^2      PI
----------  +  --------  =  -----
2              2          4

so
+-                    _____-+
|  arcsin(1)      1\/1-1^2  |
4|  ----------  +  --------  |= PI
|      2              2    |
+-                        -+

• 04-28-2002
Lynux-Penguin
WHAT THE ****
WAIT!!!
Code:

+-        -+
| arcsin(1) |
4| --------- | = PI
|    2    |
+-        -+

you can do that in C right?
• 04-28-2002
Lynux-Penguin
let me withdrawl the mathematical idiotism
arcsin(1) = PI/2
so
2(arcsin(1)) = PI

but arcsin in C uses the constant PI defined by math.h
so it is back to the drawing board.

hey, might as well right some math on CONES while I am at it.

j/k
• 04-28-2002
fyodor
5 seconds on yahoo picked up hundreds of relevant and useful sites...ask me if you need help on the exact query terms.

 damn I always get beat making sarcastic posts [/edit]
• 04-28-2002
ygfperson
ditto
• 04-28-2002
sean345
Quote:

pi = 2 ( integral(sqrt(1-x^2)dx, from -1 to 1)
When I tried this it came out to close to but not exactly PI. If you want to go 100 or even 1000 digits then you will need something more acurate. This was wrong on the 7th digit.

- Sean
• 04-28-2002
Lynux-Penguin
but it can't be wrong because your taking the area of a circle who's radius is 1 which is PI

The integral is for area under the curve and because
R^2=Y^2+X^2 = Circle
Y(x)=sqrt(1-x^2)
integrate that and you get PI/2
so 2 * that = PI exact
but the problem is
whenever you integrate on a machine the machine has a CONSTANT PI that is built in

Yahoo eh?

and yes i have memorized the search patterns.
• 04-28-2002
toaster
uh...
PI is circumference divided by diameter, I think.
or
const long double PI = 4 * arctan(1);
const long double PI = 2 * arcsin(1);
const long double PI = arccos(-1);

// PI = 180 degrees (in terms of radians and degrees)

I could be wrong, though.
• 04-28-2002
RobR
From planet-source-code.

Does this help??

Code:

//**************************************
//INCLUDE files for :Precise Calculation of Pi
//**************************************
iostream.h
math.h
//**************************************
// Name: Precise Calculation of Pi
// Description:This code calculates an estimated value of Pi using the Leibnitz series (which is basically a power series expansion of a trigonometric function which allows to estimate Pi very well)
// By: Eli
//
//
// Inputs:n/a
//
// Returns:Prints the estimated value of Pi
//
//Assumes:n/a
//
//Side Effects:n/a
//This code is copyrighted and has limited warranties.
//for details.
//**************************************

#include <iostream.h>
#include <math.h>
#define NUM_OF_ELEMENTS 20000
int main()

{
double pi = 0;
// Calculating pi/4
for (long int n = 1; n <= NUM_OF_ELEMENTS; n++)

{
pi += (double) pow(-1, n+1)/(2*n-1);
}
// Calculating pi
pi *= 4;
cout << "Estimated PI value (" << NUM_OF_ELEMENTS << " elements of Leibnitz series): "<< pi;
return 0;
}

• 04-28-2002
Lynux-Penguin
umm the last source code outputted:

Estimated PI Value (20000 elements of Leibnitz Series): 3.14154

I have more digits memorized
3.14159265358979323...
• 04-28-2002
RobR
LOL.... guess next time I should try b4 I post. Figured it meant 2000 places. Oh well.
• 04-28-2002
fyodor
Why do you not just write your own program to do it? There are a plethora of sites with the necessary summations for you. Its a pretty trivial problem to implement them, and I'm sure that lots of people will be glad to help you if you have any difficulties. If all you want is the binaries for some reason, then you might as well go to one of the many websites that contain the value of pi to immense length.
• 04-28-2002
Lynux-Penguin
I think the real problem is the memory allocation required for PI
the last source can compute pi to quite some distance
add a few zero's to the Constant and there you go
BUT THE PROGRAM TAKES FOREVER IF YOU DO
but it still only displays 3.14159
because the allocation available for a double however if you debug it in Linux you can see the whole thing which is pretty accurate.