integer division rounding

Marcin 'Qrczak' Kowalczyk qrczak at knm.org.pl
Tue Jul 17 07:09:10 EDT 2001


Tue, 17 Jul 2001 17:47:38 +0930, Michael Lunnay <mlunnay at ihug.com.au> pisze:

> Which is 'mathematically' correct then?

Donald E. Knuth said (in "Concrete Mathematics") about div/mod with
negative arguments: beware of programming languages which use a
different definition than Python!

He didn't actually mention Python as an example, but described directly
how it should work.

BTW, Haskell has both: div/mod as in Python and quot/rem as in C.
In C89 it was unspecified which way it works, but in C99 it is now
specified to work "incorrectly". Intel processors natively implement
the "incorrect" variant.

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



More information about the Python-list mailing list