Modulo operator : differences between C and Python

Cimarron Taylor cimarron+google at taylors.org
Sun Mar 10 23:42:32 EST 2002


> Anybody have any idea why this is?
> Erik

I encountered this as well in an application which needed to
verify the results of a C program.  Python seems to be counting
"down" from y if x<0.  I simply compensated for this with
the following function:  

        def mod(x,y):
            m = x%y
            if m==0 or x>0: return m
            return m-y

Another thing to watch out for when comparing results from Python and
C include is overflow/underflow behavior of the math operations.

Cim



More information about the Python-list mailing list