PEP0238 lament

Tim Hochberg tim.hochberg at ieee.org
Mon Jul 23 18:53:42 EDT 2001


"David Eppstein" <eppstein at ics.uci.edu> wrote:
> So what problems was PEP 238 proposed for anyway?
> I still haven't seen even one good example where int/int->float semantics
> is the right thing to do.

That's odd -- you must exist in a completely different part of compuspatial
continuum than I do. In my experience when I define a function that involves
division I generally want it to either compute using float-division or
floor-division[1]. I know which type of division I want when I write the
function, and it doesn't depend on what the inputs as[2]. I don't think I've
ever seen a case where I want to see the type of division change from
floor-division to float-division based on the input types.

Consider two functions: the number of pillars on a bridge and electrical
impedance per unit length:

def pillars_per_bridge(bridge_length, pillar_sep):
   return bridge_length / pillar_sep

def impedance_per_length(impedance, length):
   return return impedance / length

In the first case I _always_ want to do floor-division. In the second I
always want to do float-division. To get these to work now I need to do
something like:

def pillars_per_bridge(bridge_length, pillar_sep):
   return int(bridge_length) / int(pillar_sep)

def impedance_per_length(impedance, length):
   return (1.0*return impedance) / length

Which is not too horrible, but it is extra cruft. So let me turn your
question around. Can you give an example where you want the type of division
(float vs floor) to change depending on the type of input (int, float,
complex)? I can't, although I suspect there must be some. I also suspect
they're very rare.

When _I_ use an operator, it means just what I choose it to mean--neither
more nor
less.

or-at-least-it-should-ly yours,
-tim

[1] I'm going to use floor division rather than int-division in my
terminology because those crafty math people tell us you can't really divide
integers because there a boxing rather than a soccer venue (or maybe
vice-vera), and because the term integer-division is not well defined;
witness the difference in how integer division is done in C and python.

[2] As long as they're "numbers". Whatever that means on a given day.






More information about the Python-list mailing list