Golden ratio/Convergence: Difference between revisions

Removed Lua version
(→‎{{header|Lua}}: Flagged as incorrect)
(Removed Lua version)
Tag: Manual revert
Line 1,167:
Error (approx) : 2.722811719173566624681571006109388407808876983723400587864054809516456794284321e-26
</pre>
 
=={{header|Lua}}==
{{incorrect|Lua|The task specifically asks for iteration until successive values differ by 10^-5.}}
<p>When representated as a 64-bit floating point value, it takes 38 iterations before the iterated value is indistinguishable from the calculated one.</p>
<p>The stipulation to stop when the error is less than 1e-5 is presumably to prevent calculations with arbitrary-precision values from continuing infinitely.</p>
<p>Since such data types are unavailable in the core Lua language, we may as well continue to the natural limitation.</p>
<syntaxhighlight lang="lua">local phi, iters = 1, 0
repeat
phi = 1 + 1 / phi
iters = iters + 1
until phi == (1 + math.sqrt(5)) / 2
print("Value of phi: " .. phi)
print("Iterations required: " .. iters)</syntaxhighlight>
{{out}}
<pre>Value of phi: 1.6180339887499
Iterations required: 38</pre>
 
=={{header|M4}}==
31

edits