Arithmetic-geometric mean/Calculate Pi: Difference between revisions
Content added Content deleted
m (Delphy → Delphi) |
No edit summary |
||
Line 646: | Line 646: | ||
Iteration: 4 Diff: 3.05653257536554156111405386493810661E-0010 Pi: 3.14159265358979323846636060270664556 |
Iteration: 4 Diff: 3.05653257536554156111405386493810661E-0010 Pi: 3.14159265358979323846636060270664556 |
||
Iteration: 5 Diff: 3.71721942712928151094186846648146566E-0021 Pi: 3.14159265358979323846264338327951628 |
Iteration: 5 Diff: 3.71721942712928151094186846648146566E-0021 Pi: 3.14159265358979323846264338327951628 |
||
</pre> |
|||
=={{header|FutureBasic}}== |
|||
<syntaxhighlight lang="futurebasic"> |
|||
double a, c, g, t, p |
|||
double apprpi |
|||
short i |
|||
// Initial values |
|||
a = 1 |
|||
g = sqr(0.5) |
|||
p = 1 |
|||
t = 0.25 |
|||
//Iterate just 3 times |
|||
for i = 1 to 3 |
|||
c = a |
|||
a = ( a + g ) / 2 |
|||
g = sqr( c * g ) |
|||
c -= a |
|||
t -= ( p * c^2 ) |
|||
p *= 2 |
|||
apprpi = (( a + g )^2) / ( t * 4 ) |
|||
print "Iteration "i": ", apprpi |
|||
next |
|||
print "Actual value:",pi |
|||
handleevents |
|||
</syntaxhighlight> |
|||
{{output}} |
|||
<pre> |
|||
Iteration 1: 3.140579250522169 |
|||
Iteration 2: 3.141592646213543 |
|||
Iteration 3: 3.141592653589794 |
|||
Actual value: 3.141592653589793 |
|||
</pre> |
</pre> |
||