RosettaCodeData/Task/Approximate-equality/FreeBASIC/approximate-equality.basic

26 lines
634 B
Plaintext

#include "string.bi"
Dim Shared As Double epsilon = 1
Sub eq_approx(a As Double,b As Double)
Dim As Boolean tmp = Abs(a - b) < epsilon
Print Using "& & &";tmp;a;b
End Sub
While (1 + epsilon <> 1)
epsilon /= 2
Wend
Print "epsilon = "; Format(epsilon, "0.000000000000000e-00")
Print
eq_approx(100000000000000.01, 100000000000000.011)
eq_approx(100.01, 100.011)
eq_approx(10000000000000.001/10000.0, 1000000000.0000001000)
eq_approx(0.001, 0.0010000001)
eq_approx(0.000000000000000000000101, 0.0)
eq_approx(Sqr(2)*Sqr(2), 2.0)
eq_approx(-Sqr(2)*Sqr(2), -2.0)
eq_approx(3.14159265358979323846, 3.14159265358979324)
Sleep