v2 / vlib / v / tests / assign / cross_assign_with_parentheses_test.v
17 lines · 14 sloc · 309 bytes · 6488041a749df9762348d019c4223908c476f2e2
Raw
1import math
2
3const ep = 1e-14
4
5fn 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
13fn test_cross_assign_with_parentheses() {
14 ret := agm(1.0, 1.0 / math.sqrt2)
15 println(ret)
16 assert ret == 0.8472130847939792
17}
18