Note: I’ve already read this topic, but I don’t understand it and it doesn’t provide a solution I could use. I’m terrible with number problems.
What’s a simple way to generate Pi to what number of decimals a user wants? This isn’t for homework, just trying to complete some of the projects listed here:
A classic algorithm for calculating digits of
piis the Gauss-Legendre algorithm. While it is not as fast as some of the more modern algorithms it does have the advantage of being understandable.Let
Then
Then
Here (
=.means “approximately equal to”) This algorithm exhibits quadratic convergence (the number of correct decimal places doubles with each iteration).I’ll leave it to you to translate this to C# including discovering an arbitrary-precision arithmetic library.