code not true?

Alan Daniels daniels at mindspring.com
Sat Apr 22 21:17:17 EDT 2000


On Sat, 22 Apr 2000 14:02:21 GMT, Mark Hammond
<mhammond at skippinet.com.au> wrote:

[snip...]
>Of all the solutions to this problem, this does strike me as one of
>the best - simply remove equality testing al together for floating
>point.

Are you sure of this? It would be awful confusing for a programming
newbie to do:

x = 5.0
y = 5.0 # Later on down in the code.
x == y  # And even further...

And get an exception thrown. All the "why doesn't this work?" messages
we've seen about floating point have to do with doing manipulation of
the numbers and *then* having them not work.

For 0.07 * 100 to not be the same as 7.0 is understandable, because
that's just how floating point works on CPUs today: Not all numbers
are representable in IEEE format. But to outlaw asking if 7.0 is equal
to 7.0 definitely goes against the principle of least suprise. And
learning that floating-point math sometimes leads to slight numerical
errors is an important lesson that newbie programmers shouldn't be
shielded from.

I like Python 1.6's handling of it better: Showing floating point
values in all their slightly-inaccurate glory seems like the better
plan.

-- 
============================================================
Alan Daniels
daniels at mindspring.com



More information about the Python-list mailing list