ScratchData LogoScratchData
Back to DadOfMrLog's profile

Pi Calc, 1000s of digits

DADadOfMrLog•Created September 28, 2013
Pi Calc, 1000s of digits
257
209
7181 views
View on Scratch

Instructions

AAARRGGHHH!! There's a hard limit of 10240 characters for variables now! This means this will no longer work for more than about 10000 digits :( :( :( :( ---------------------------------------- Calculates thousands of digits of the maths constant, pi. Choose how many digits (100 to 100000) and let it go... WARNING: calculating 100000 digits may take a couple of days! A good number to start with is about 1000. Click through the info slides in project to find out how it works. (Apologies for Scratch's slightly inconsistent placing of the text between normal & fullscreen players, which means the power superscripts don't all quite fit exactly where they're meant to...)

Description

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

Project Details

Project ID12754597
CreatedSeptember 28, 2013
Last ModifiedMay 3, 2014
SharedSeptember 30, 2013
Visibilityvisible
CommentsAllowed