14 lines
352 B
Text
14 lines
352 B
Text
create or replace function agm(a0, g0) as (
|
|
with recursive
|
|
rec as (
|
|
select a0::DOUBLE as a, g0::DOUBLE as g, a - g as diff
|
|
union all
|
|
select a, g, (a - g) as diff
|
|
from ( select ((a + g)/2) as a, sqrt(a * g) as g, diff
|
|
from rec )
|
|
where diff > 1e-15 )
|
|
select (a + g)/2
|
|
from rec
|
|
where diff <= 1e-15
|
|
limit 1
|
|
);
|