Approximate equality: Difference between revisions

no edit summary
No edit summary
Line 406:
</pre>
 
=={{header|Forth}}==
{{works with|GForth | 0.7.9_20211014}}
Genuine Forth word :
f~ ( r1 r2 r3 – flag ) float-ext “f-proximate”
ANS Forth medley for comparing r1 and r2 for equality: r3>0: f~abs; r3=0: bitwise comparison; r3<0:
<lang forth>
1e-18 fconstant cepsilon
: test-f~ ( f1 f2 -- )
1e-18 \ epsilon
f~ \ AproximateEqual
if ." True" else ." False" then
;
</lang>
{{out}}
<pre>
100000000000000.01e 100000000000000.011e test-f~ True
100.01e 100.011e test-f~ False
10000000000000.001e 10000.0e f/ 1000000000.0000001000e test-f~ False
0.001e 0.0010000001e test-f~ False
0.000000000000000000000101e 0.0e test-f~ True
2.0e fdup fsqrt fswap fsqrt f* 2.0e test-f~ False
2.0e fdup fsqrt fnegate fswap fsqrt f* -2.0e test-f~ False
3.14159265358979323846e 3.14159265358979324e test-f~ True
</pre>
=={{header|Fortran}}==
Compare against the Python function documented at https://www.python.org/dev/peps/pep-0485/#proposed-implementation,
Anonymous user