[Python-ideas] PEP 485: A Function for testing approximate equality

Zero Piraeus schesis at gmail.com
Tue Jan 27 18:42:27 CET 2015


:

Disclaimer: I haven't read all of this thread, and what I have read I've
sometimes skimmed (and apparently some of the discusion was offlist
anyway).

On Mon, Jan 26, 2015 at 10:24:07PM -0800, Chris Barker wrote:
> 
> So what I haven't seen yet is an example use case where you really
> need the symmetric case -- i.e. it matters that is_close(a,b) is
> guaranteed to be the same as is_close(b,a).
> 
> Does anyone have a use-case??

Once this exists, at some point somebody's going to write:

    def near_miss(data, tol):
        pairs = itertools.combinations(data.values(), 2)
        return any(is_close(a, b, tol) for a, b in pairs)

and then (if it's asymmetric) be very surprised when this:

    example = {'A': 0.01, 'B': 2.34, 'C': 5.67, 'D': 5.68, 'E': 9.99}

    near_miss(example, 1/568)

returns True half the time and False the other half. That's going to be
a really nasty heisenbug when it crops up in real code, especially since
it's only going to change for each invocation of the interpreter.

I don't really buy the idea that it'll almost always be used with
tolerances of 1e-8 etc. If it goes in the stdlib, it'll be used in ways
no-one here anticipates (and which are not, intuitively, "wrong").

 -[]z.

-- 
Zero Piraeus: absit invidia
http://etiol.net/pubkey.asc


More information about the Python-ideas mailing list