Re:How to compare floats in Python
by PennRobotics on Wednesday March 30, 2022 @02:13PM
(#30858770)
Naive because it's just the easiest way. (Also, right, I forgot abs.)
I imagine the downside with a chosen "epsilon" (which I used as an alias for any tolerance) is that it can be truncated on some machines, plus this equation on its own doesn't do relative accuracy.
On an LEGO EV3, Python's float is 1e38 max with 7 significant digits.
I've never run into problems, which is why I keep using it, too.
Also, I wouldn't use epsilon, because that is a very small number and is related to representation of numbers. I would instead use a larger "tolerance" value, in `if |a-b| < tol ...` because that indicates the expected accuracy of your algorithm (unless you're really working with 1e-80 tolerance?). But TFA explains that.
But back to point (a) is that not reasonable? (If not, I've got some code to change... :)