[Python-Dev] nice() (original) (raw)

Greg Ewing greg.ewing at canterbury.ac.nz
Mon Feb 13 07:34:57 CET 2006


Smith wrote:

When teaching some programming to total newbies, a common frustration is how to explain why a==b is False when a and b are floats computed by different routes which ``should'' give the same results (if arithmetic had infinite precision).

This is just a special case of the problems inherent in the use of floating point. As with all of these, papering over this particular one isn't going to help in the long run -- another one will pop up in due course.

Seems to me it's better to educate said newbies not to use algorithms that require comparing floats for equality at all. In my opinion, if you ever find yourself trying to do this, you're not thinking about the problem correctly, and your algorithm is simply wrong, even if you had infinitely precise floats.

Greg



More information about the Python-Dev mailing list