Re: [Python-ideas] [Python-Dev] The Case Against Floating Point ==

As per Aahz's suggestion, I'm moving this discussion here, from Python-Dev. (Thanks Aahz!) Mark Dickinson wrote: this sort of cases, whatever the decision may be.
Still, I believe it is worth discussing.
While checking against a==0.0 (and other similar conditions) before dividing will indeed protect from outright division by zero, it will enlarge any error you will have in the computation. I guess it would be better to do the same check for 'a is small' for appropriate values of 'small'.
If suggestion no. 1 is accepted, always return True. If no. 2 is accepted, raise an exception. Checking x==x is as meaningful as checking x==y.
Actually, one of the reasons I thought about this subject in the first place, was dict lookup for floating point numbers. It seems to me that it's something you just shouldn't do. As for your examples, I believe these two should both raise an exception. This is even worse than normal comparison - here you are checking against the hash of a floating point number. So if you do that in the current implementation, there's a good chance you'll get unexpected results. If you do that given the implementation of suggestion 1, you'll have a hard time make set work.
------------------------- Imri Goldberg www.algorithm.co.il/blogs www.imri.co.il ------------------------- Insert Signature Here -------------------------

1. python users have to know, that representation of float has some problems 2. python users must not care about internal float representation Solution "2." is not good, because someday somebody will complain, that computer calculations are not accurate (some scientist who was not willing about learning how computer stores floats). It is better to choose "1." -- beginers will have to accept that computer is not able to store every real number, because floats are stored as binary numbers. Maybe operator "==" for floats should be deprecated, and people should use something like "!~" or "=~", and they should be able to set precission for float numbers?

1. python users have to know, that representation of float has some problems 2. python users must not care about internal float representation Solution "2." is not good, because someday somebody will complain, that computer calculations are not accurate (some scientist who was not willing about learning how computer stores floats). It is better to choose "1." -- beginers will have to accept that computer is not able to store every real number, because floats are stored as binary numbers. Maybe operator "==" for floats should be deprecated, and people should use something like "!~" or "=~", and they should be able to set precission for float numbers?
participants (2)
-
Imri Goldberg
-
Leszek Dubiel