Why isn't Python king of the hill?

E. Mark Ping emarkp at CSUA.Berkeley.EDU
Sat Jun 2 12:49:58 EDT 2001


In article <slrn9hi2o1.sa.grante at tuxtop.visi.com>,
Grant Edwards <grante at visi.com> wrote:
>On Sat, 2 Jun 2001 09:42:34 +0200, Alex Martelli <aleaxit at yahoo.com> wrote:
>>And it is (on any FP system respecting IEEE 754 -- and any
>>other FP system I've ever heard about).
>
>I know that it is.  But when you start depending on that fact,
>you're doomed.

That's silly and just plain wrong.  You should depend on understanding
how FP works.  And in this case, 1.0 + 2.0 == 3.0 every time on every
platform that I've run into--I don't know that because I just happened
to try it out, but rather I know how the FP works on those platforms
and know that it is correct.

>>> should always treat floating point operations as if there are
>>> small random numbers being thrown in at every step.  So you
>>
>>I think this is exactly what Kahan describes as one of the
>>widespread (and false) myths about floating point.
>
>Of course it is not true.  But if you pretend it is, you've got
>a much better chance of producing working code.

You should definitely read Pete Becker's articles in the June, July
and October 2000 issues of The C/C++ Users Journal.  He explains why
you're statement is insufficient and incorrect.  For instance, two
very large numbers might really be the same, but be off by a bit.
Checking the difference of the values will yield another large number,
and a method like "IsCloseTo" will incorrectly fail.

Really, floating point arithmetic has well-defined semantics; guessing
and treating them as if they have random components is the lazy and
error-prone way to use them.
-- 
Mark Ping                     
emarkp at soda.CSUA.Berkeley.EDU 



More information about the Python-list mailing list