The comparisons for Parser reals are fuzzy checks based on the
tolerances in place for the problem. In your case, 416.25 and 415.84
have a relative difference of .00098, which is below the tolerance of
.001, and so these ARE equal as far as fuzzy tolerances are concerned.
Since a < b, a == b, a > b are supposed to be mutually exclusive
conditions, when fuzzy math is used, a < b means that two conditions
are met: a < b in the absolute sense and a != b in the fuzzy sense.
Similarly for a > b. The idea is to prevent a < b and a == b from
BOTH being true simultaneously
So the effect you are obtaining is correct, but not what you expected.
If you really want to do an absolute rather than fuzzy check, use
$profitLower->value < $profitUpper->value which will force a
You definitely do NOT want to do string comparisons for these things.
As for your other example, I'm not sure what it means to "fail" or
"test correctly" in this case, since I don't know what the values of $b
and $a are, and whether they are Parser Reals or not. (Both of which
will make a difference.) If they are Parser Reals, then the numeric
equality is a fuzzy equality based on the current tolerances.
If they aren't Parser Reals, I don't think you'd want to do $qv1 ==
int($qv1) either, since you really DO want to do a fuzzy check (but
perhaps with sharper tolerances) rather than a floating point equality
If they are Parser Reals, you might try $qv1 - int($qv1) == 0 instead,
since that will kick in the zero tolerance rather than the standard
relative tolerance for non-zero numbers. This suggests you could also
use $profitLower - $profitUpper < 0 rather than $profitLower <
$profitUpper as well to get fuzzy checks against zero (where the
zeroLevelTolerance takes over).
<| Post or View Comments |>