Integer division and remainder

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Wed Aug 15 04:45:07 EDT 2001


14 Aug 2001 16:20:57 -0700, Paul Rubin <phr-n2001 at nightsong.com> pisze:

>    7 / 3 =  2
>   -7 / 3 = -3
> 
> This is kind of strange.  Normally you expect (-a)/b to be the same as -(a/b).
> That's what happens in most languages, where division rounds towards zero:

Donald Knuth says that Python is right and C is wrong, and I agree
with him here. I expect a%b for positive b to return a value in the
range [0, b).

-- 
 __("<  Marcin Kowalczyk * qrczak at knm.org.pl http://qrczak.ids.net.pl/
 \__/
  ^^                      SYGNATURA ZASTĘPCZA
QRCZAK



More information about the Python-list mailing list