Golden ratio/Convergence: Difference between revisions
Content added Content deleted
m (→{{header|ALGOL 68}}: typo) |
mNo edit summary |
||
Line 1,384: | Line 1,384: | ||
I ran this with shen-scheme. |
I ran this with shen-scheme. |
||
<pre>[1.6180327868852458 14 -1.2018646493583418e-6]</pre> |
<pre>[1.6180327868852458 14 -1.2018646493583418e-6]</pre> |
||
=={{header|V (Vlang)}}== |
|||
<syntaxhighlight lang="Rust"> |
|||
import math |
|||
fn main() { |
|||
limit := 1e-5 |
|||
mut old_phi := 1.0 |
|||
mut iters := 0 |
|||
mut phi, mut actual_phi := f64(0), f64(0) |
|||
for { |
|||
phi = 1 + 1 / old_phi |
|||
iters++ |
|||
if math.abs(phi - old_phi) <= limit {break} |
|||
old_phi = phi |
|||
} |
|||
println("Final value of phi : ${phi:.14f}") |
|||
actual_phi = (1.0 + math.sqrt(5.0)) / 2.0 |
|||
println("Number of iterations : ${iters}") |
|||
println("Error (approx) : ${phi - actual_phi:.14f}") |
|||
} |
|||
</syntaxhighlight> |
|||
{{out}} |
|||
<pre> |
|||
Final value of phi : 1.61803278688525 |
|||
Number of iterations : 14 |
|||
Error (approx) : -0.00000120186465 |
|||
</pre> |
|||
=={{header|Wren}}== |
=={{header|Wren}}== |