Against PEP 240

Robin Becker robin at jessikat.fsnet.co.uk
Wed May 30 12:25:35 CEST 2001


In article <m37kyzji8z.fsf at chinon.cnrs-orleans.fr>, Konrad Hinsen
<hinsen at cnrs-orleans.fr> writes
>"Alex Martelli" <aleaxit at yahoo.com> writes:
>
>> Having 7.35 MEAN 7.35 rather than 7.3499999999999996 is
>> an issue of another conceptual order of magnitude, except to
>> people who have already been "brainwashed" by experience.
>
>In spite of years of experience with floats, I guess I haven't been
>brainwashed yet, I completely agree that a default arithmetic
>compatible with common sense is a Good Thing. But I also worry about
>compatibility with existing code, of which there is a lot by now.
>Whatever number system is chosen, I'd like to make sure that
>

I cannot disagree with Alex on this either, but I agree with Konrad on
the points below.

>0) There will be enough automatic conversion to make existing
>   C modules using floats work without changes.
>1) Scripts that used to run in seconds don't take days.
>2) Scripts that used to run in 1 MB of RAM don't require 1 GB.
>
>I have never used rational numbers in calculations, but I do have used
>gmpy quite a lot recently for high-precision floating point
>computations, and the CPU time overhead is enormous. One of my scripts
>now takes five days (with 100 bits) rather than two hours with
>standard floats.
>

Tim Peters made similar points about the surprise factor, if naive users
are worried about the apparently inexact nature of the current
computations then I think they might be very worried about the inexact
nature of the time-space requirement for exact calculations.

As it stands the PEP demands rationals for all float constants, several
have noted that it might be better to use decimal (I assume fixed point)
which would at least limit the time space problem while maintaining the
apparent accuracy for simple calculations. I'm not sure about that at
all.

>There is another more general problem with adding more number types to
>Python, namely that the current type coercion mechanism makes it very
>difficult to avoid bad surprises. Making sure that a+b is the same as
>b+a for any combination of number types a and b is not at all trivial.
Alex claims that anyone trying out Newton's method is able to make the
right things float. If the wrong coercion strategy is used then it may
be converted straight back to rational making the common numerical
operations rather time consuming. Looking at PEP 228 doesn't seem to
inform me as to what will actually happen when I start using float &
rational (or inexact and exact). It's quite easy to write 10.0**99, but
how is it going to be floated etc etc.
-- 
Robin Becker



More information about the Python-list mailing list