Arithmetic-geometric mean: Difference between revisions

Add Seed7 example
m (Added Raven code for Arithmetic-geometric mean)
(Add Seed7 example)
Line 955:
agm(1, math.sqrt(2)/2, 1e-15)
</lang>
 
=={{header|Seed7}}==
<lang seed7>$ include "seed7_05.s7i";
include "float.s7i";
include "math.s7i";
 
const func float: agm (in var float: a, in var float: g) is func
result
var float: agm is 0.0;
local
const float: iota is 1.0E-7;
var float: a1 is 0.0;
var float: g1 is 0.0;
begin
if a * g < 0.0 then
raise RANGE_ERROR;
else
while abs(a - g) > iota do
a1 := (a + g) / 2.0;
g1 := sqrt(a * g);
a := a1;
g := g1;
end while;
agm := a;
end if;
end func;
const proc: main is func
begin
writeln(agm(1.0, 2.0) digits 6);
writeln(agm(1.0, 1.0 / sqrt(2.0)) digits 6);
end func;</lang>
 
{{out}}
<pre>
1.456791
0.847213
</pre>
 
=={{header|Tcl}}==