Hilbert's Hotel

Diskussionsforum zur Unendlichkeit: Theismus, Atheismus, Primzahlen, Unsterblichkeit, das Universum...
Discussing Infinity: theism and atheism, prime numbers, immortality, cosmology, philosophy...

Gamestudio Links
Zorro Links
Newest Posts
Zorro 2.70
by jcl. 09/29/25 09:24
optimize global parameters SOLVED
by dBc. 09/27/25 17:07
ZorroGPT
by TipmyPip. 09/27/25 10:05
assetHistory one candle shift
by jcl. 09/21/25 11:36
Plugins update
by Grant. 09/17/25 16:28
AUM Magazine
Latest Screens
Rocker`s Revenge
Stug 3 Stormartillery
Iljuschin 2
Galactic Strike X
Who's Online Now
1 registered members (TipmyPip), 18,619 guests, and 5 spiders.
Key: Admin, Global Mod, Mod
Newest Members
krishna, DrissB, James168, Ed_Love, xtns
19168 Registered Users
Previous Thread
Next Thread
Print Thread
Rate Thread
Calculating Pi #205319
05/05/08 20:36
05/05/08 20:36
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
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)

 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 ?

Re: Calculating Pi [Re: Oxy] #205324
05/05/08 20:47
05/05/08 20:47
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
http://crd.lbl.gov/~dhbailey/bbp-formula.bmp gives you the n-th digit of pi without having to calculate the n-1 previous digits.

Last edited by Joey; 05/05/08 20:47.
Re: Calculating Pi [Re: Joey] #205325
05/05/08 20:52
05/05/08 20:52
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
Ok, cool, thanks

Re: Calculating Pi [Re: Oxy] #205648
05/07/08 18:53
05/07/08 18:53
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
how does that work, by the way? i only see a function which diverges very quickly to pi.

Re: Calculating Pi [Re: Joey] #205674
05/07/08 21:45
05/07/08 21:45
Joined: May 2008
Posts: 301
Oxy Offline OP
Senior Member
Oxy  Offline OP
Senior Member

Joined: May 2008
Posts: 301
The code I posted comes actually from Euler, who found out that the sum
of the infinite chain of natural numbers:

1/(1*1) + 1/(2*2) + 1/(3*3) ....

is exactly (PI*PI)/6

Thus we can calculate PI (using computers calculation power to get
the value of the infinite chain)

Re: Calculating Pi [Re: Oxy] #205724
05/08/08 08:07
05/08/08 08:07
Joined: Jan 2003
Posts: 4,615
Cambridge
Joey Offline
Expert
Joey  Offline
Expert

Joined: Jan 2003
Posts: 4,615
Cambridge
i meant the formula i gave you.

have you tried 3 + 1/3 - 1/5 + 1/7 - 1/9...? this should be also faster than your approach.


Moderated by  jcl, Lukas, old_bill, Spirit 

Kompaktes W�rterbuch des UnendlichenCompact Dictionary of the Infinite


Powered by UBB.threads™ PHP Forum Software 7.7.1