Jump to content

Approximate equality: Difference between revisions

Approximate equality in Yabasic
m (Automated syntax highlighting fixup (second round - minor fixes))
(Approximate equality in Yabasic)
Line 2,068:
8. 3.1415926535897900E+000 3.1415926535897900E+000 true
</pre>
 
=={{header|Yabasic}}==
<syntaxhighlight lang="yabasic">// Rosetta Code problem: http://rosettacode.org/wiki/Approximate_equality
// by Jjuanhdez, 09/2022
 
epsilon = 1.0
while (1 + epsilon <> 1)
epsilon = epsilon / 2
wend
 
print "epsilon = ", epsilon
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(sqrt(2)*sqrt(2), 2.0)
eq_approx(-sqrt(2)*sqrt(2), -2.0)
eq_approx(3.14159265358979323846, 3.14159265358979324)
end
 
sub eq_approx(a, b)
tmp = abs(a - b) < epsilon
print tmp, " ", a, " ", b
end sub</syntaxhighlight>
 
=={{header|zkl}}==
2,133

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.