RosettaCodeData/Task/Arithmetic-geometric-mean/Common-Lisp/arithmetic-geometric-mean.lisp
2023-07-01 13:44:08 -04:00

5 lines
188 B
Common Lisp

(defun agm (a0 g0 &optional (tolerance 1d-8))
(loop for a = a0 then (* (+ a g) 5d-1)
and g = g0 then (sqrt (* a g))
until (< (abs (- a g)) tolerance)
finally (return a)))