RosettaCodeData/Task/Arithmetic-geometric-mean/Jq/arithmetic-geometric-mean-1.jq
2017-09-25 22:28:19 +02:00

9 lines
239 B
Text

def naive_agm(a; g; tolerance):
def abs: if . < 0 then -. else . end;
def _agm:
# state [an,gn]
if ((.[0] - .[1])|abs) > tolerance
then [add/2, ((.[0] * .[1])|sqrt)] | _agm
else .
end;
[a, g] | _agm | .[0] ;