Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,14 @@
|
|||
import math
|
||||
|
||||
proc agm(a, g: float,delta: float = 1.0e-15): float =
|
||||
var
|
||||
aNew: float = 0
|
||||
aOld: float = a
|
||||
gOld: float = g
|
||||
while (abs(aOld - gOld) > delta):
|
||||
aNew = 0.5 * (aOld + gOld)
|
||||
gOld = sqrt(aOld * gOld)
|
||||
aOld = aNew
|
||||
result = aOld
|
||||
|
||||
echo agm(1.0,1.0/sqrt(2.0))
|
||||
|
|
@ -0,0 +1,20 @@
|
|||
from math import sqrt
|
||||
from strutils import parseFloat, formatFloat, ffDecimal
|
||||
|
||||
proc agm(x,y: float): tuple[resA,resG: float] =
|
||||
var
|
||||
a,g: array[0 .. 23,float]
|
||||
|
||||
a[0] = x
|
||||
g[0] = y
|
||||
|
||||
for n in 1 .. 23:
|
||||
a[n] = 0.5 * (a[n - 1] + g[n - 1])
|
||||
g[n] = sqrt(a[n - 1] * g[n - 1])
|
||||
|
||||
(a[23], g[23])
|
||||
|
||||
var t = agm(1, 1/sqrt(2.0))
|
||||
|
||||
echo("Result A: " & formatFloat(t.resA, ffDecimal, 24))
|
||||
echo("Result G: " & formatFloat(t.resG, ffDecimal, 24))
|
||||
Loading…
Add table
Add a link
Reference in a new issue