Golden ratio/Convergence: Difference between revisions

Added XPL0 example.
(Added Applesoft, GW-BASIC, Minimal BASIC, MSX Basic, PureBasic, QBasic, Quite BASIC and True BASIC)
(Added XPL0 example.)
Line 1,354:
<pre>
Final value of phi : 1.61803278688525
Number of iterations : 14
Error (approx) : -0.00000120186465
</pre>
 
=={{header|XPL0}}==
{{trans|Go}}
XPL0's real = float64 = double
<syntaxhighlight lang "XPL0">include xpllib; \for Print
 
real OldPhi, Phi, Limit, ActualPhi;
int Iters;
[OldPhi := 1.0;
Iters := 0;
Limit := 1e-5;
loop [Phi := 1.0 + 1.0/OldPhi;
Iters := Iters+1;
if abs(Phi-OldPhi) <= Limit then
quit;
OldPhi := Phi;
];
Print("Final value of phi : %2.14f\n", Phi);
ActualPhi := (1.0 + sqrt(5.0)) / 2.0;
Print("Number of iterations : %d\n", Iters);
Print("Error (approx) : %2.14f\n", Phi-ActualPhi);
]</syntaxhighlight>
{{out}}
<pre>
Final value of phi : 1.61803278688525
Number of iterations : 14
Error (approx) : -0.00000120186465
290

edits