You can lower the value of Internal`$EqualTolerance
:
Block[{Internal`$EqualTolerance = 0},
0.999999999999988 >= 1.0
]
False
This can lead to unexpected behaviors too:
Block[{Internal`$EqualTolerance = 0},
0.1 + 0.2 == 0.3
]
False
Maybe there's a better sweet spot that fits your needs. For these two examples, this works:
Block[{Internal`$EqualTolerance = Internal`$SameQTolerance},
0.999999999999988 >= 1.0
]
False
Block[{Internal`$EqualTolerance = Internal`$SameQTolerance},
0.1 + 0.2 == 0.3
]
True
If you have a nice representative sample of values you're comparing, you can estimate a value for Internal`$EqualTolerance
by plotting. These two examples return correct comparisons for values between Log10[5/3]
and Log10[108]
:
correctEquals[x_?NumericQ] :=
Block[{Internal`$EqualTolerance = x},
Boole[Not[0.999999999999988 >= 1.0] && (0.1 + 0.2 == 0.3)]
]
Plot[correctEquals[x], {x, 0, Internal`$EqualTolerance}]
a == b
, checka - b == 0
(same with <, >). The normal rules of arithmetic don't necessarily apply when you're working with floating point numbers. $\endgroup$0.999999999999988`17. >= 1.`17.
givesFalse
See alsoPossible Issues
in the documentation ofEqual
. $\endgroup$