[Python-ideas] [Python-Dev] The Case Against Floating Point ==

Imri Goldberg lorgandon at gmail.com
Fri Mar 14 10:01:28 CET 2008


Mark Dickinson wrote:

> On Thu, Mar 13, 2008 at 6:18 PM, Imri Goldberg <lorgandon at gmail.com 
> <mailto:lorgandon at gmail.com>> wrote:
>
>     This makes changing == behavior to an epsilon comparison more
>     involved.
>     I still think it is feasible, but will require much more
>     consideration.
>
>
> Okay, now I am going to be negative. :-)
>
> I really think that there's essentially zero chance of == and != ever 
> changing
> to 'fuzzy' comparisons in Python.  I don't want to discourage you from 
> working
> out possible details as an academic exercise, or perhaps with some other
> (Python-like?) language in mind, but I just don't see it ever 
> happening in Python.
> Maybe I'm wrong, in which case I hope other python people will tell me so,
> but I think pursuing this is, in the end, going to be a waste of time.
>

Alright, I agree it's a good idea to drop the proposal to changing 
floating point == into an epsilon compare.
What about issuing a warning though?
Consider the following course of action. It is the one with the least 
changes:

== for regular floating point numbers now issues a warning, but still 
works. This warning might be turned off. All other operators are left 
unchanged.

Do you think this should be dropped as well?
Just for my own code, I think I'd like this behavior. I still consider 
floating point == a potential bug, and this helps me catch it, in the 
absence of the 'ideal static checker'.


> Containers would be affected in peculiar ways.  I think people would be
> really surprised to find that 1.0+2e-16 *was* an element of the set {1.0},
> or that 1.0 and 1.0+2e-16 weren't allowed to be different keys in a dict.
> And how on earth do you check for set or dict membership under the 
> hood?
>

I think that right now containers behave in peculiar ways when used with 
FP numbers.
Take set for example - you might as well just use list instead of it.
When you consider dict, then doing d[x] might not return the result you 
actually want.

> I don't know of any other language that has successfully done this, even
> though I've seen the idea floated many times for different languages.
> That doesn't mean much, since I only know a small handful of the many
> hundreds (thousands?) of languages out there.  If you know a
> counterexample, I'd be interested to hear it.
>
> Mark
Don't know of a good counterexample. I agree that before changing the 
behavior of == to fuzzy comparison, you'll want  experience with that 
kind of change.

Cheers,
Imri


-------------------------
Imri Goldberg
www.algorithm.co.il/blogs
www.imri.co.il
-------------------------
Insert Signature Here
-------------------------





More information about the Python-ideas mailing list