Page 1 of 1

Calculating pi

Posted: Sun Sep 29, 2013 6:55 pm
by andrewferguson
Hi,
How do I calculate pi using LiveCode?
I know that LiveCode has the built in pi constant, but I want more decimal places.
Also, I know I could just copy and paste pi from a website into my program, but the whole fun is having it go on and on and on...

Andrew

Re: Calculating pi

Posted: Sun Sep 29, 2013 7:03 pm
by Dixie

Code: Select all

on mouseUp
   set the numberformat to 0.000000000000000
   put 22/7 into fld 1
end mouseUp
Dixie

Re: Calculating pi

Posted: Tue Oct 01, 2013 1:13 am
by [-hh]
..........

Re: Calculating pi

Posted: Tue Oct 01, 2013 2:07 am
by dunbarx
One of the oddest is:

1/π = 2√2 / 9801 * ∑ (4k)! (1103 + 26390k) / (k!)^4 * 396^4k

The sum taken from 0 to infinity.

Ramanujan did this in his head.

This looks like it could be readily worked out with LC. A repeat loop could run the summation for a while.

Craig

EDIT. I have a feeling the digits get out of hand pretty soon...