C# – First steps with C# and .NET – part 054.

By | 03/09/2022

This tutorial will show you how to calculate the Pi math number using a spigot algorithm from Stanley Rabinowitz and Stan Wagon:
A spigot algorithm is an algorithm for computing the value of a transcendental number (such as π or e) that generates the digits of the number sequentially from left to right providing increasing precision as the algorithm proceeds. Spigot algorithms also aim to minimize the amount of intermediate storage required. The name comes from the sense of the word “spigot” for a tap or valve controlling the flow of a liquid. Spigot algorithms can be contrasted with algorithms that store and process complete numbers to produce successively more accurate approximations to the desired transcendental., see Spigot algorithm Wikipedia.
This algorithm can be written like this:

You will see this source code for this algorithm is very simple:

The result of this running algorithm is this:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.