modulo - 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.
解决方案
推荐阅读
- emacs - 如何为 c 文件制作 Emacs 自动填充代码
- arduino - 使用 Arduino Nano 的串行接口与 ESP8266 通信——当前挂起
- sql-server - TSQL如何将连接表中的列与group by连接起来
- c - 在 C 中读取二进制有符号短问题
- c - 编译器为限制指针指向的内存而采取的措施
- scala - 是否将隐式执行上下文传递给 .par 操作?
- ibm-mq - IBM MQ 是否有任何未解决的错误列表?
- javascript - 日期验证(日期不应在现有日期范围内)
- r - 如何基于 R 中长格式的数据框创建具有不同列长度的 Markdown 表?
- html - 纯 CSS 范围滑块,其背景颜色根据进度/值而变化