RosettaCodeData/Task/Arithmetic-geometric-mean/Common-Lisp/arithmetic-geometric-mean.lisp

6 lines
188 B
Common Lisp
Raw Permalink Normal View History

2013-04-10 16:57:12 -07:00
(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)))