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

Terry Reedy tjreedy at udel.edu
Wed Jan 21 22:29:10 CET 2015


On 1/21/2015 6:59 AM, Steven D'Aprano wrote:
> On Wed, Jan 21, 2015 at 09:27:39AM -0200, Joao S. O. Bueno wrote:
>
>> 1)  Implement a Number class that behaves as a float number, and does
>> the fuzzy comparisons automatically.
>
> -1 on this.

>
> (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.

The proper operation of sets (and dicts) depends on == being transitive. 
  Letting D0 = Decimal(0), we once had 0.0 == 0 and 0 == D0 but 0.0 != 
D0 (now fixed) and the result was obscure bugs.  One of the design 
criteria for, I believe, Enums was that == be transitive.

-- 
Terry Jan Reedy




More information about the Python-ideas mailing list