Pi Calc, 1000s of digits

6,893
0
Publicado 2013-09-30
** UPDATE (ready for pi-day 2014) ** Added timer.
As far as pi calculations go, Scratch is a really slow way to do it because it has to interpret the script and manipulate the really long strings of digits in very inefficient ways.
(A decent home computer now can work out a million digits in just a few seconds using more modern algorithms - e.g. see:
http://www.apfloat.org/apfloat_java/applet/pi.html )

However, Scratch is considerably faster than my ZX Spectrum was - back in 1984, that took about three weeks to calculate 25000 digits (using the same algorithm as this project), and I coded that in Z80a assembly language.

It's also a lot faster than doing it with pen & paper... :)

Credit to Klingenstierna for the Machin-like formula used here:
pi/4 = 8*atan(1/10) - atan(1/239) - 4*atan(1/515)

Credit to Taylor for his series expansion, so the inverse tan function (i.e. atan) can be worked out to high precision using just long addition, subtraction, and simple division:
atan(1/x) = 1/x - 1/(3*x^3) + 1/(5*x^5) - 1/(7*x^7) + ....

For more information about the method used here, and calculating pi in general, see wikipedia links:
http://en.wikipedia.org/wiki/Machin-like_formula
http://en.wikipedia.org/wiki/Approximations_of_pi
http://en.wikipedia.org/wiki/Chronology_of_computation_of_pi