Does python suck or I am just stupid?
David Eppstein
eppstein at ics.uci.edu
Sat Feb 22 13:12:07 EST 2003
In article <41948401.0302221000.6257443f at posting.google.com>,
andy at takecover.net (Andy Mroczkowski) wrote:
> I've been tearing my hair out over a bug(?) I've come across. I've
> only been programming in Python for a few months so I'm no expert.
> I've seen the same behavior in Python2.2 on several different
> machines. Instead of banging my head against the wall even more, I
> thought I would ask the community for help.
This is not a problem with the language, and the same thing would happen
if you wrote that code in any other language. It's a problem with your
understanding of floating point arithmetic.
One of the better discussions of what floating point means and how it
works turns out to be in the Python docs:
http://www.python.org/doc/current/tut/node14.html
For a little more technical detail, see http://citeseer.nj.nec.com/goldberg91what.html
But the basic issue here is, floating point numbers are not infinitely
precise, so you can't expect == to work with two floats that were
computed by two different expressions.
--
David Eppstein http://www.ics.uci.edu/~eppstein/
Univ. of California, Irvine, School of Information & Computer Science
More information about the Python-list
mailing list