我有以下代码:
NSInteger index1 = (stop.timeIndex - 1); //This will be -1
index1 = index1 % [stop.schedule count]; // [stop.schedule count] = 33
所以我有表达式 -1 % 33。这应该给我 32,但给了我 3...我已经在调试器中仔细检查了这些值。有人有什么想法吗?
最佳答案
在 C 中,取模运算符不适用于负数。 (它给出了余数,而不是像它的通用名称所暗示的那样进行模运算。)
关于c - Obj 中奇怪的 mod 行为。 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3418053/