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.

3
  • I checked that earlier. IMO, it doesn't understand the general (mathematical) principle behind it. Commented Jan 11, 2020 at 12:37
  • 1
    Does this answer your question? The modulo operation on negative numbers in Python Commented Jan 11, 2020 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. Commented Jan 11, 2020 at 12:43

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.