[Python-ideas] Floating point "closeness" Proposal Outline

Chris Barker - NOAA Federal chris.barker at noaa.gov
Wed Jan 21 16:50:19 CET 2015


> But it really sounds like you want a full interval arithmetic
> class, which is a lot more than just fuzzy comparisons.

Indeed -- this is way out of scope for the current conversation/PEP.

Please start another thread if you think this is worth pushing forward.

But as this would be a whole new Numeric-like class, the way forward
would probably be to impliment it, put it up on pypi, and if it sees
significant use, propose it for inclusion in the stdlib.

The current proposal is for a simple, generally useful
"fuzzy"comparison.  It is quite specifically for use with the existing
float object ( and other related types ).

PEP on the way -- stay tuned.

-Chris









>
> There are two problems with overriding == in this way:
>
> (1) What do you mean by "is close"? Do you mean that they are within
> 0.0001 or 0.00000001 or within 10000.0? With a binary operator == there
> is no easy way to specify an error tolerance, which means you're stuck
> with using a language-wide default which is very unlikely to be suitable
> for your application. A context manager is one solution, but that's
> still awkward. Think about doing:
>
>    a == b or x == y
>
> where the a, b comparison and x, y comparison have different tolerances.
>
>
> (2) Fuzzy equality means that there are situations where:
>
>    a == b and b == c
>
>    but
>
>    a != c
>
> The language APL tried to turn this into a feature:
>
>    The intransitivity of [tolerant] equality is well known in practical
>    situations and can be easily demonstrated by sawing several pieces
>    of wood of equal length. In one case, use the first piece to measure
>    subsequent lengths; in the second case, use the last piece cut to
>    measure the next. Compare the lengths of the two final pieces.
>    — Richard Lathwell, APL Comparison Tolerance, APL76, 1976
>
>
> but I'm not so sure. If we introduced a new comparison operator (perhaps
> the Unicode symbol ≈ or the ASCII ~= ?) I'd be less concerned but I
> think overriding == for fuzzy equality is a mistake.
>
>
> --
> Steve
> _______________________________________________
> Python-ideas mailing list
> Python-ideas at python.org
> https://mail.python.org/mailman/listinfo/python-ideas
> Code of Conduct: http://python.org/psf/codeofconduct/


More information about the Python-ideas mailing list