simple math question

Terry Reedy tjreedy at udel.edu
Sat Feb 11 16:35:23 EST 2006


"John Salerno" <johnjsal at NOSPAMgmail.com> wrote in message 
news:RuWdnVmaD4Q23XPeRVn-tw at rcn.net...
> Can someone explain to me why the expression 5 / -2 evaluates to -3,
> especially considering that -2 * -3 evaluates to 6?

With same sign int division, one can think of the result as either being 
rounding down or rounding to zero.  With mixed sign int division, rounding 
to zero becomes rounding up, so the language designer has to choose being 
consistent with one or the other but not both.  There are pluses and 
minuses either way and different language designers have made different 
choices between the two.

Guido's rational was posted some years ago but I forget.  You might be able 
to find something in Google's c.l.p archives, or on the web in general.

Terry Jan Reedy






More information about the Python-list mailing list