Builtin Float Epsilon? (was: Re: Does python suck or I am just stupid? )

Tim Peters tim_one at email.msn.com
Sun Feb 23 02:57:29 EST 2003


[attribution lost]
> Please see
> http://www.python.org/cgi-bin/faqw.py?req=show&file=faq04.098.htp
>
> (Then change the u==x comparison from a strict equality check, as
> prescribed therein.)

[djw]
> I've always wondered, given this fact,

It's not a fact -- equality testing with floats can be thoroughly
appropriate.  It depends on the app.  Likewise "fuzzy equality" testing can
be appropriate with integers too, depending on the app.

> why is there an equivalence operator for floats?

It's a (strict) equality operator across all Python's numeric types.
Difficulties in practice come from not understanding the types, not from the
operators refusing to guess what you really want.

> (or, maybe the == operator should do the epsilon range check for you
> somehow).

That can be useful in an expert's hands, but for a non-expert I expect would
serve mostly to further confuse an already-garbled view of numeric reality.

> ...
> Seems like this would keep more people from running into this 'problem'.

If so, it would most likely delay the point at which they first become aware
that they have no real idea what they're doing.  Better to learn that early,
if they care about getting acceptably accurate results.  If you want a fuzzy
comparion, there's nothing to stop you for programming exactly the degree of
fuzziness you want, appropiate for each specific comparion.






More information about the Python-list mailing list