[Python-ideas] [Python-Dev] The Case Against Floating Point ==
Mark Dickinson
dickinsm at gmail.com
Fri Mar 14 02:01:10 CET 2008
On Thu, Mar 13, 2008 at 6:18 PM, Imri Goldberg <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.
Some reasons, and then I'll shut up:
Too much complication and magic implicit stuff going on
behind the scenes. In a fuzzy a == b there are hidden choices about the
fuzziness scheme and the amount of fuzz to allow, and those choices
are going to confuse the hell out of newbie and expert programmers alike.
As above, you'd have to choose defaults for the fuzziness, and by Murphy's
Law those defaults would be wrong for almost everybody else's particular
applications, meaning that almost everybody else would have to go away
and learn about how to change or turn off the fuzziness.
Fundamental and well-understood laws (trichotomy, transitivity of equality)
would break. It's really unclear how the other comparison operators
would be affected. If 1.0 == 1.0+2e-16 returns True, shouldn't
1.0 >= 1.0+2e-16 also return True?
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 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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20080313/c451aed3/attachment.html>
More information about the Python-ideas
mailing list