Here's an interactive Python example to help clarify the previous response: >>> a = 5 >>> b = 10 >>> q , r = divmod(a,b) >>> q 0 >>> r 5 >>> a = -a >>> a -5 >>> q , r = divmod(a,b) >>> q -1 >>> r 5 >>> b*q + r # division algorithm -5 >>> -5 == a True >>>