One particular problem with floating-point arithmetic is that comparison for equality often fails when you would expect it to succeed. For this reason approximate equality is often preferred (but you still have to know what you are doing). Also note that IEEE NaNs may compare differently from what you might expect. The comparison words are:
f~rel
( r1 r2 r3 – flag ) gforth-0.5 “f~rel”
Approximate equality with relative error: |r1-r2|<r3*|r1+r2|.
f~abs
( r1 r2 r3 – flag ) gforth-0.5 “f~abs”
Approximate equality with absolute error: |r1-r2|<r3.
f~
( r1 r2 r3 – flag ) floating-ext “f-proximate”
Forth-2012 medley for comparing r1 and r2 for equality: r3>0:
f~abs
; r3=0: bitwise comparison; r3<0: fnegate f~rel
.
f=
( r1 r2 – f ) gforth-0.2 “f-equals”
f<>
( r1 r2 – f ) gforth-0.2 “f-not-equals”
f<
( r1 r2 – f ) floating “f-less-than”
f<=
( r1 r2 – f ) gforth-0.2 “f-less-or-equal”
f>
( r1 r2 – f ) gforth-0.2 “f-greater-than”
f>=
( r1 r2 – f ) gforth-0.2 “f-greater-or-equal”
f0<
( r – f ) floating “f-zero-less-than”
f0<=
( r – f ) gforth-0.2 “f-zero-less-or-equal”
f0<>
( r – f ) gforth-0.2 “f-zero-not-equals”
f0=
( r – f ) floating “f-zero-equals”
f0>
( r – f ) gforth-0.2 “f-zero-greater-than”
f0>=
( r – f ) gforth-0.2 “f-zero-greater-or-equal”