Integer division (was: Case-sensitivity... (was: Damnation!))

François Pinard pinard at iro.umontreal.ca
Sun May 21 17:39:30 CEST 2000


Robin Becker <robin at jessikat.demon.co.uk> writes:

> In addition I would also like 1/2 to remain integer divide.

I'm a bit less sure about this one.

Of course, I would have to revise much of my code, but when I write 1/2,
it is explicit in my thoughts that I really mean int(1/2) -- at least not
considering problems induced by negative operands :-).  For one, I would not
mind having to write the `int()' explicitely, I guess it would just make
the code more legible.  When, in Python, I see `i / j', I have to trace
the type of operands to make sure that truncation will, or will not occur.

Mathematicians' opinion surely has stronger value than mine here, but I do
remember having written any generic algorithm in which it is meaningful
that `i / j' sometimes mean truncating, sometimes not, depending on the
type of the operands.  So spelling `int()' would not be a problem for me.

No doubt that I would not like having to revise existing code!  But also,
as the current `i / j' gives access to useful hardware instruction, a new
`int(i/j)' might incur unwelcome overhead for something that once was faster.

-- 
François Pinard   http://www.iro.umontreal.ca/~pinard






More information about the Python-list mailing list