>From a numerical standpoint, floats shouldn't generally be compared using
equality.  I came across a bug at work yesterday where I had written:

    if not delta:
        return 0.0

where delta was a floating point number.  After a series of calculations
piling up round-off error delta took on a value on the order of 1e-8.  Not
zero, but it should have been.  The fix was easy enough:

    if abs(delta) < EPSILON:
        return 0.0

for a suitable value of EPSILON.

That got me to thinking...  I'm sure I have plenty of other similar mistakes
in my code.  (Never was much of a numerical analysis guy...)  What if there
was a picky-float setting that generated warnings if you compared two floats
using "==" (or implicitly using "not")?  Does that make sense to try for
testing purposes?  The implementation seemed straightforward enough:

    http://python.org/sf/1478364

I'm sure at the very least the idea needs more thought than I've given it.
It's just a half-baked idea at this point.

Skip
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to