Goto 10 RetroComputing: Atari and more

Share this post

Pi Day: Estimating the Value of Pi with BASIC

www.goto10retro.com

Pi Day: Estimating the Value of Pi with BASIC

3.14

Paul Lefebvre
Mar 14
4
Share this post

Pi Day: Estimating the Value of Pi with BASIC

www.goto10retro.com

It's Pi day (March 14, or 314 in the US) and one question you may be wondering is “how is Pi calculated?”

Before getting in to that, just a quick Goto 10 reminder: This is the last week of the Goto 10 Anniversary sale. Save 20% (about $10) on a yearly subscription. With a paid subscription you get double the retro content!

Measuring circles can give a rough estimate, but an infinite series is perhaps a better and more common way to do it. As described on Calculating Pi at MathCareers.org.uk, the Nilakantha Series works pretty well. Its formula looks like this:

Nilakantha Series: π = 3 + 4 / (2×3×4) − 4 / (4×5×6) + 4 / (6×7×8) − 4 / (8×9×10) + …

You ought to be able to figure out a pattern from that. And it’s a short leap to convert that to BASIC code. Here’s some short BASIC code

1
that calculates Pi using the Nilakantha Series:

The above code correctly calculated the first 7 digits of Pi in about 47 seconds. Unfortunately, even on modern computers calculating significantly more digits of Pi with this method is not really practical using the floating point data type used in most programming languages.

Related:

Goto 10 RetroComputing: Atari and more
Happy Pi Day
Happy Pi Day (March 14 or 3/14 as we write here in the US)! This reminded me of an article in ANALOG Computing that draws a circle using smaller and smaller lines. After a little digging, the article is called CalcPi and is from the February 1986 ANALOG Computing (Issue 39…
Read more
a year ago · 3 likes · Paul Lefebvre
1

Based on code I originally wrote in Xojo.

Share this post

Pi Day: Estimating the Value of Pi with BASIC

www.goto10retro.com
Previous
Next
Comments
TopNewCommunity

No posts

Ready for more?

© 2023 Paul Lefebvre
Privacy ∙ Terms ∙ Collection notice
Start WritingGet the app
Substack is the home for great writing