I thought I understood basic arithmetic!
I've just learned that Ruby and Python (and, I'm told Tcl) define integer division of or by a negative number differently that C and Java do. Consider the quotient -7/3. Java gives -2. Ruby gives -3.
Modulo is different, too: In Java -7%3 is -1. But in Ruby it is 2.
I think I prefer the C and Java version of division, because it has the nice property that: -x/y = -(x/y). In general, this is not the case in Ruby.
On the other hand, Ruby's integer division can be explained with a simple rule. For the quotient q=x/y, we can say that q is the largest integer such that q*y<=x. For this rule, "largest" and "less than" have their obvious meanings: closest to positive infinity and closer to negative infinity.
Maybe there is an equally succinct and general definition of integer division for C and Java, but it looks to me as if it requires special-casing the signs of the operands or defining "less than" as "closer to zero".
I haven't done much programming in Ruby or Python, but I suspect that this isn't the kind of thing that lis likely to cause bugs in practice. I don't know when I actually do integer division with negative operands. It reminds me, however of Josh Bloch's recent blog post and drives home his point that integer arithmetic is not as simple as it appears!
(Ruby and Python aficionados are invited to use the comments to explain why your language of choice does the right thing :-)
Update: comments are now closed. Comment spammers have found the entry