This has to do with the rounding rules. Consider a simpler example:
>>> -3/(-2)
1
>>> -3/2*-1
2
1.5
is rounded down to 1
, and -1.5
is rounded down to -2
. Consistent, in a way.
Plain or long integer division yields an integer of the same type; the result is that of mathematical division with the ‘floor’ function applied to the result.
If you want a floating point result in Python 2.x, you need either an explicit conversion (or just use float literals), or do from __future__ import division
. In Python 3.x, division always produces a float (ref).