首页 > 解决方案 > Understanding the modulo operation for negative integers

问题描述

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.

标签: modulo

解决方案


推荐阅读