RosettaCodeData/Task/Arithmetic-geometric-mean/Futhark/arithmetic-geometric-mean.futhark
2023-07-01 13:44:08 -04:00

11 lines
208 B
Text

import "futlib/math"
fun agm(a: f64, g: f64): f64 =
let eps = 1.0E-16
loop ((a,g)) = while f64.abs(a-g) > eps do
((a+g) / 2.0,
f64.sqrt (a*g))
in a
fun main(x: f64, y: f64): f64 =
agm(x,y)