Approximate equality: Difference between revisions
Content added Content deleted
m (Fixed a typo.) |
(Approximate equality in FreeBASIC) |
||
Line 350: | Line 350: | ||
-2.000000000000000444E+00 == -2.000000000000000000E+00 ? T |
-2.000000000000000444E+00 == -2.000000000000000000E+00 ? T |
||
3.141592653589793116E+00 == 3.141592653589793116E+00 ? T</pre> |
3.141592653589793116E+00 == 3.141592653589793116E+00 ? T</pre> |
||
=={{header|FreeBASIC}}== |
|||
{{trans|AWK}} |
|||
<lang freebasic>#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</lang> |
|||
=={{header|Go}}== |
=={{header|Go}}== |