PEP0238 lament

Grant Edwards grante at visi.com
Sun Jul 22 22:46:07 EDT 2001


On Sun, 22 Jul 2001 20:10:47 -0400, Tim Peters <tim.one at home.com> wrote:
>[Tim]
>> The current integer division loses information silently and without
>> a trace.
>
>[Grant Edwards]
>> No, it doesn't.
>
>Of course it does, but note that I'm using "information" in its technical
>sense.  Current int division is a many-to-one mapping, so necessarily loses
>information.

Right, but the same is true for float division.  Therefore, the
fact that integer division loses information isn't a valid
reason to prefer floating point division for the "/" operator
when it is used on two integers.

int + int => int
int * int => int
int - int => int
int & int => int
int | int => int

[so far, so good]

int / int => int
  or
int / int => float

Which of the two is the least astonishing?  In my mind, the
"int" result is the least astonishing, but like I said, I'm
quite used to using integer arithmetic, and if I want floats,
I use floats.

>Whether 1/2 would return a float is still open.

Right.  IMO, having operators coerce their operands like that
is too much like the "magic" that goes on in Perl.  I suppose
it's only a bit worse that 1/2.0 coercing the "1" to a float,
but I'm not too kean on _that_ either. ;)  Quite a few hours of
debugging time could have been saved over the past 30 years if
1/2.0 wasn't legal in C.

I'd be pretty happy if mixing a float and an int threw an
exception.  When I run lint on C programs, I usually want it to
complain about that sort of thing. I don't generally like types
changing "automagically" behind the scenes.

>Or maybe you needed integer semantics -- I can't guess. Doesn't
>much matter to the current debate.  If you bought a hand
>calculator that truncated division results to integers, would
>you be happy with that?

Mine does.  If it didn't I'd toss it in the trash.  Of course
the operands are always integers, so it's not that surprising.
There's a way to get it to do floating point, but I don't do
that very often.

>That's what informs the expectations of the generations after
>us.

Kids these days...

-- 
Grant Edwards                   grante             Yow!  I'm in direct contact
                                  at               with many advanced fun
                               visi.com            CONCEPTS.



More information about the Python-list mailing list