Modulo operator : differences between C and Python

Kragen Sitaker kragen at pobox.com
Tue Mar 19 03:32:02 EST 2002


Tim Peters <tim.one at comcast.net> writes:
> Python defines the result of i%j to have the same sign as j; what C requires
> depends on which year's C standard you're looking at (it was left up to
> implementers' discretion before the 1999 standard); the C implementations I
> use return a result with i's sign, and I usually curse them for that.

This is a result of C being a portable assembly language; % returns
whatever the underlying remainder register has after a divide, which
generally has i's sign.




More information about the Python-list mailing list