[Python-ideas] Way to check for floating point "closeness"?

Stephen J. Turnbull stephen at xemacs.org
Fri Jan 16 04:28:43 CET 2015


Neil Girdhar writes:

 > The symmetric error that people are proposing in this thread has no
 > intuitive meaning to me.

There are many applications where the goal is to match two values,
neither of which is the obvious standard (eg, statistical tests
comparing populations, or even electrical circuits, where it may be
important that two components be matched to within 1%, although the
absolute value might be allowed to vary by up to 10%).  Symmetric
error is appropriate for those applications.  Symmetric error may be
less appropriate for applications where you want to hit an absolute
value, but it's (provably) not too bad.

By "provably not too bad" I mean that if you take the word "close" as
a qualitative predicate, then although you can make the "distance"
explode by taking the "actual" to be an order of magnitude distant in
absolute units, you'll still judge it "not close" (just more so, but
"more so" is meaningless in this qualitative context).  On the other
hand, for values that *are* close (with reasonable tolerances) it
doesn't much matter which value you choose as the standard: "most" of
the time you will get the "right" answer (and as the tolerance gets
tighter, "most" tends to a limit of 100%).

The generic "are_close()" function should be symmetric.  I suppose it
might also to useful to have an "is_close_to()" function that is
asymmetric.



More information about the Python-ideas mailing list