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

djw dwelch91 at no.spam.attbi.com
Sat Feb 22 19:33:59 CET 2003

> 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.)
> -Peter

I've always wondered, given this fact, why is there an equivalence 
operator for floats? (or, maybe the == operator should do the epsilon 
range check for you somehow). It seems to be strange to have an valid 
operator for a type that you should never in practice use. Maybe you 
should be able to write something like:

sys.floatepsilon = 0.000000001 # or maybe some nice default value

u = 1.0000000000001
v = 1.0

if u == v: # uses the system float epsilon test instead of "true" test

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


More information about the Python-list mailing list