RosettaCodeData/Task/Golden-ratio-Convergence/FreeBASIC/golden-ratio-convergence.basic
2023-07-01 13:44:08 -04:00

39 lines
1,016 B
Text

Sub using_Single
Dim As Integer iter = 0
Dim As Single phi0 = 1.0f
Dim As Single phi1
Dim As Single diferencia
Do
phi1 = 1.0f + (1.0f / phi0)
diferencia = Abs(phi1 - phi0)
phi0 = phi1
iter += 1
Loop While (1.0e-5f < diferencia)
Print "Using type Single --"
Print Using "Result: #.########## after ## iterations"; phi1; iter
Print Using "The error is approximately #.##########"; phi1 - (0.5f * (1.0f + Sqr(5.0f)))
End Sub
Sub using_Double
Dim As Integer iter = 0
Dim As Double phi0 = 1.0
Dim As Double phi1
Dim As Double diferencia
Do
phi1 = 1.0 + (1.0 / phi0)
diferencia = Abs(phi1 - phi0)
phi0 = phi1
iter += 1
Loop While (1.0e-5 < diferencia)
Print "Using type Double --"
Print Using "Result: #.########## after ## iterations"; phi1; iter
Print Using "The error is approximately #.##########"; phi1 - (0.5 * (1.0 + Sqr(5.0)))
End Sub
using_Single
Print
using_Double
Sleep