[Matrix-SIG] Numeric Nits

Ivan Frohne frohne@gci.net
Fri, 25 Jun 1999 10:19:22 -0800


Of course an integer division operation should exist, but it should not
be the one associated with the general division operator.

Fortran, and other strongly typed languages, may safely utilize a
general division operator.  If J and K are Fortran integers, then
so is J / K.  But in Python, who knows what type J and K are?
You may intend them to be integers, but if the previous
assignment to J was, for example, J = math.sqrt(100), J is now
a double.  If you want to be sure that J / K is an integer, you must
use int(J) / int(K).  Or, if you don't want 1 / 2 == 0, use
float(J) / float(K).  

In Python, the general division operator is unsafe.  But to require
a different division operator for every numerical type (integer, float
and complex) would be inconvenient.  And maybe convenience ranks
higher than safety.  That's above my pay grade.

--Ivan Frohne