Floating point numbers (in all languages, not just Tcl) represent most numbers somewhat inaccurate. Thus, they should usually not be compared for equality, since this is really unlikely. Instead, you should check if the two values ββare in a certain amount from each other (the amount is known as epsilon and takes into account that there are small errors in floating point calculations).
In your code you can write this:
set epsilon 0.001; # Small, but non-zero if { $epsilon < $n_rval && $n_rval < 1-$epsilon} { set onextensionFlag 0;# inside clipping area } elseif {abs($n_rval) < $epsilon || abs(1-$n_rval) < $epsilon} { set onextensionFlag 1 ;# inside clipping area (but on point) } elseif { $n_rval >= 1+$epsilon || $n_rval <= -$epsilon } { set onextensionFlag 2 ;# outside clipping area } else { set onextensionFlag 3 ;# consider inside clipping area }
Basically, think in terms of a number line where you change points to small intervals:
0 1 ββββββββββββββββ|ββββββββββββββββ|ββββββββββββββββ
to
0-Ξ΅ 0+Ξ΅ 1-Ξ΅ 1+Ξ΅ βββββββββββββββ(β)ββββββββββββββ(β)βββββββββββββββ
To check what range you are in, follow it.
source share