by steve (12 Submissions)
Category: Math/Dates
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Sat 1st May 2004
Date Added: Mon 8th February 2021
Rating: (1 Votes)
Calculate the number Pi
' You will need a ListBox and a Command Button
'Can you explain to me how this works ?
' [email protected]
' **********************
' This was used by Tamura and Kanada for their calculation
' to 16 million places for the number Pi
' it is based on Gauss's study of the arithmetic-geometric
' mean of two numbers. It has the property that the
' number of correct digits approx. doubles with each circuit
' loop , so that going around a mere 19 times gives Pi
' correct to over 1 million decimal places
'********From the Penquin Dictionary of Curious and
' ******* Interesting numbers by David Wells
' *** this book was in error I believe I have corrected this
A = 1
X = 1
B = 1 / Sqr(2)
C = 1 / 4
Y = ((A + B) ^ 2)
' These four list items are used to check your initial values
' if you wish to
'List1.AddItem A
'List1.AddItem X
'List1.AddItem B
'List1.AddItem C
' Rem This is the first approximation
List1.AddItem ((A + B) ^ 2)
For TrialCount = 1 To 5
Y = A
A = (A + B) / 2
B = Sqr(B * Y)
C = C - (X * (A - Y) ^ 2)
X = 2 * X
Y = (((A + B) ^ 2) / C / 4)
List1.AddItem Y
' ' ****** Your accuracy is dependent on your formatting
' ' options
Next
End Sub