RosettaCodeData/Task/Arithmetic-geometric-mean/UNIX-Shell/arithmetic-geometric-mean-1.sh
2023-07-01 13:44:08 -04:00

12 lines
240 B
Bash

function agm {
float a=$1 g=$2 eps=${3:-1e-11} tmp
while (( abs(a-g) > eps )); do
print "debug: a=$a\tg=$g"
tmp=$(( (a+g)/2.0 ))
g=$(( sqrt(a*g) ))
a=$tmp
done
echo $a
}
agm $((1/sqrt(2))) 1