print AGM(1, 1 / sqr(2)) end function AGM(a, g) Do ta = (a + g) / 2 g = sqr(a * g) x = a a = ta ta = x until a = ta return a end function