Posted By: Oxy
Calculating Pi - 05/05/08 20:36
Our infinite most beautiful number:
Here a way to calculate PI in Java.
(btw, LiteC is just using some different expressions for loops,
square-roots and float values)
gives us: 3.1415921761250813 (well its close)
Are there suggestions to calculate it quicker ?
Here a way to calculate PI in Java.
(btw, LiteC is just using some different expressions for loops,
square-roots and float values)
Code:
//calculating PI
double sum=0;
double adder=0;
for (int i=0; i<2000000;i++) //the more, the more exact
{
adder+=1;
sum+=(1/(adder*adder));
}
sum = sum*6;
sum=Math.sqrt(sum); //quare root, the result is PI !!
System.out.println("Pi is:"+sum);
gives us: 3.1415921761250813 (well its close)
Are there suggestions to calculate it quicker ?