Anonymous user
Arithmetic-geometric mean: Difference between revisions
no edit summary
(→{{header|Raku}}: another solution) |
imported>Lacika7 No edit summary |
||
(2 intermediate revisions by 2 users not shown) | |||
Line 412:
210 REM ********************
220 PRINT AGM(1, 1 / SQR(2))
230 END</syntaxhighlight>
{{out}}
<pre> .84721308479398 </pre>
==={{header|Applesoft BASIC}}===
Same code as [[#Commodore_BASIC|Commodore BASIC]]
The [[#BASIC|BASIC]] solution works without any changes.
==={{header|BASIC256}}===
Line 435 ⟶ 436:
end function</syntaxhighlight>
{{out}}
<pre>0.84721308479</pre>
==={{header|BBC BASIC}}===
Line 456 ⟶ 455:
</syntaxhighlight>
{{out}}
<pre>0.8472130847939792</pre>
==={{header|Chipmunk Basic}}===
Line 536 ⟶ 533:
{{out}}
<pre> 0.8472130847939792</pre>
==={{header|Gambas}}===
{{trans|FreeBASIC}}
<syntaxhighlight lang="vbnet">Public Sub Main()
Print AGM(1, 1 / Sqr(2))
End
Function AGM(a As Float, g As Float) As Float
Dim t_a As Float
Do
t_a = (a + g) / 2
g = Sqr(a * g)
Swap a, t_a
Loop Until a = t_a
Return a
End Function</syntaxhighlight>
==={{header|GW-BASIC}}===
Line 576 ⟶ 595:
</syntaxhighlight>
{{out}}
<pre>0.84721308
0.84721308479397904</pre>
==={{header|Minimal BASIC}}===
{{trans|Commodore BASIC}}
{{works with|IS-BASIC}}
<syntaxhighlight lang="qbasic">10 LET A = 1
20 LET G = 1 / SQR(2)
30 GOSUB 60
40 PRINT A
50 STOP
60 LET T = A
70 LET A = (A + G) / 2
80 LET G = SQR(T * G)
90 IF A < T THEN 60
100 RETURN
110 END</syntaxhighlight>
{{out}}
<pre> .84721308</pre>
==={{header|MSX Basic}}===
{{works with|MSX BASIC|any}}
The [[#Commodore BASIC|Commodore BASIC]] solution works without any changes.
The [[#GW-BASIC|GW-BASIC]] solution works without any changes.
==={{header|PureBasic}}===
Line 598 ⟶ 638:
EndIf</syntaxhighlight>
{{out}}
<pre> 0.8472130847939792</pre>
==={{header|QuickBASIC}}===
Line 617 ⟶ 655:
END FUNCTION</syntaxhighlight>
{{out}}
<pre>.8472131</pre>
==={{header|Quite BASIC}}===
{{trans|Commodore BASIC}}
<syntaxhighlight lang="qbasic">10 LET A = 1
20 LET G = 1 / SQR(2)
30 GOSUB 100
40 PRINT A
50 END
100 LET T = A
110 LET A = (A + G) / 2
120 LET G = SQR(T * G)
130 IF A < T THEN 100
140 RETURN</syntaxhighlight>
{{out}}
<pre>0.8472130847939792</pre>
==={{header|Run BASIC}}===
Line 687 ⟶ 738:
END</syntaxhighlight>
{{out}}
<pre>.84721308</pre>
==={{header|VBA}}===
Line 712 ⟶ 761:
==={{header|VBScript}}===
{{trans|BBC BASIC}}
<syntaxhighlight lang="vb">Function agm(a,g)
Do Until a = tmp_a
tmp_a = a
Line 722 ⟶ 770:
End Function
WScript.Echo agm(1,1/Sqr(2))</syntaxhighlight>
{{Out}}
<pre>0.847213084793979</pre>
==={{header|Yabasic}}===
<syntaxhighlight lang="vb">print AGM(1, 1 / sqrt(2))
end
sub AGM(a, g)
repeat
ta = (a + g) / 2
g = sqrt(a * g)
x = a
a = ta
ta = x
until a = ta
return a
end sub</syntaxhighlight>
{{out}}
<pre>0.847213</pre>
Line 3,468 ⟶ 3,533:
=={{header|Wren}}==
{{trans|Go}}
<syntaxhighlight lang="
var agm = Fn.new { |a, g|
|