| 1 | import math |
| 2 | |
| 3 | const ep = 1e-14 |
| 4 | |
| 5 | fn agm(aa f64, gg f64) f64 { |
| 6 | mut a, mut g := aa, gg |
| 7 | for math.abs(a - g) > math.abs(a) * ep { |
| 8 | a, g = (a + g) * .5, math.sqrt(a * g) |
| 9 | } |
| 10 | return a |
| 11 | } |
| 12 | |
| 13 | fn test_cross_assign_with_parentheses() { |
| 14 | ret := agm(1.0, 1.0 / math.sqrt2) |
| 15 | println(ret) |
| 16 | assert ret == 0.8472130847939792 |
| 17 | } |
| 18 |