[docs] [issue31021] Clarify programming faq.

Charles Wohlganger report at bugs.python.org
Tue Jul 25 09:47:54 EDT 2017


Charles Wohlganger added the comment:

Modulo is defined mathematically as the remainder of Euclidian division. I.E. a positive r where a % b = r is equivalent to a = b * x + r. I think it confuses the issue to say "-190 % 12 were the mathematical equivalent -10", when that is technically incorrect.

Computer modulo uses truncated division, which is why -a % b != a % -b.

"... compilers that truncate i // j need to make i % j have the same sign as i."
i % j has the same sign as j, not i. I believe that is the typo that has caused the confusion.

I would replace the last line with :
"-190 % 12 == -10 is wrong according to the C definition for computer modulo arithmetic."

----------
nosy: +wohlganger

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue31021>
_______________________________________


More information about the docs mailing list