tweak: decrease convergence constants for faster speed.
This commit is contained in:
parent
da9a10791f
commit
6454b2eeab
BIN
wip/nim/samples
BIN
wip/nim/samples
Binary file not shown.
|
@ -29,7 +29,7 @@ proc sine(x: float): float =
|
||||||
|
|
||||||
## Arithmetic-geomtric mean
|
## Arithmetic-geomtric mean
|
||||||
proc ag(x: float, y: float): float =
|
proc ag(x: float, y: float): float =
|
||||||
let n = 128 # just some high number
|
let n = 16 # just some high number
|
||||||
var a = (x + y)/2.0
|
var a = (x + y)/2.0
|
||||||
var b = sqrt(x * y)
|
var b = sqrt(x * y)
|
||||||
for i in 0..n:
|
for i in 0..n:
|
||||||
|
@ -41,7 +41,7 @@ proc ag(x: float, y: float): float =
|
||||||
## Find m such that x * 2^m > 2^precision/2
|
## Find m such that x * 2^m > 2^precision/2
|
||||||
proc find_m(x:float): float =
|
proc find_m(x:float): float =
|
||||||
var m = 0.0;
|
var m = 0.0;
|
||||||
let precision = 64 # bits
|
let precision = 32 # bits
|
||||||
let c = pow(2.0, precision.float / 2.0)
|
let c = pow(2.0, precision.float / 2.0)
|
||||||
while x * pow(2.0, m) < c:
|
while x * pow(2.0, m) < c:
|
||||||
m = m + 1
|
m = m + 1
|
||||||
|
|
Loading…
Reference in New Issue
Block a user