RosettaCodeData/Task/Arithmetic-geometric-mean/Common-Lisp/arithmetic-geometric-mean.lisp
Ingy döt Net 764da6cbbb CDE
2013-04-10 16:57:12 -07: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)))