RosettaCodeData/Task/Arithmetic-geometric-mean/Scala/arithmetic-geometric-mean.scala

6 lines
186 B
Scala
Raw Permalink Normal View History

2013-04-10 14:58:50 -07:00
def agm(a: Double, g: Double, eps: Double): Double = {
if (math.abs(a - g) < eps) (a + g) / 2
else agm((a + g) / 2, math.sqrt(a * g), eps)
}
agm(1, math.sqrt(2)/2, 1e-15)