> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/a/arithmetic-geometric_mean.md).

# Arithmetic-geometric mean

```ruby
func agm(a, g) {
    loop {
        var (a1, g1) = ((a+g)/2, sqrt(a*g))
        [a1,g1] == [a,g] && return a
        (a, g) = (a1, g1)
    }
}

say agm(1, 1/sqrt(2))
```

#### Output:

```
0.847213084793979086606499123482191636481445910327
```
