Calculating pi

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
andrewferguson
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 184
Joined: Wed Apr 10, 2013 5:09 pm

Calculating pi

Post by andrewferguson » Sun Sep 29, 2013 6:55 pm

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

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: Calculating pi

Post by Dixie » Sun Sep 29, 2013 7:03 pm

Code: Select all

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

[-hh]
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2262
Joined: Thu Feb 28, 2013 11:52 pm

Re: Calculating pi

Post by [-hh] » Tue Oct 01, 2013 1:13 am

..........
Last edited by [-hh] on Wed Aug 13, 2014 12:11 pm, edited 1 time in total.
shiftLock happens

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10354
Joined: Wed May 06, 2009 2:28 pm

Re: Calculating pi

Post by dunbarx » Tue Oct 01, 2013 2:07 am

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...

Post Reply