0

this answer explains the modulo operation for positive numbers perfectly. But how does modulo operation work differently for negative integers? for example -1 % 60 == 59 in Python but -1 % 60 == -1 in C.

The C answer makes sense to me in that the logic is same as that for a modulo operation involving positive integers. But what's the skinny with the Python answer?

What is the general principle behind modulo operation for negative integers?

this answer doesn't explain the general principle.

TIA.

computronium
  • 445
  • 2
  • 11
  • I checked that earlier. IMO, it doesn't understand the general (mathematical) principle behind it. – computronium Jan 11 '20 at 12:37
  • 1
    Does this answer your question? [The modulo operation on negative numbers in Python](https://stackoverflow.com/questions/3883004/the-modulo-operation-on-negative-numbers-in-python) – Andra Jan 11 '20 at 12:40
  • The mathematical principle is simply that in Z/60Z, -1 = 59, so the results in C and Python are actually the same. – Jörg W Mittag Jan 11 '20 at 12:43

0 Answers0