12
votes
Accepted
Distinguishing modulo (Euclidean division) from remainder
Given the usefulness of a proper modulo operator to wrap an integer into a range [0, n) e.g. for an array index or generating a random integer in this range, I find ...
11
votes
Distinguishing modulo (Euclidean division) from remainder
There are two great articles investigating this question:
Division and Modulus for Computer Scientists by Daan Leijen
The Euclidean Definition of the Functions div and mod by Raymond Boute
In short, ...
5
votes
Accepted
Why is truncated or non-Euclidean division/modulo the norm?
The answer is largely given at the top of the answer by Jules to the question you linked:
In short, div-mod operations come in pairs satisfying the equation
...
5
votes
Distinguishing modulo (Euclidean division) from remainder
One could always take the route of C's pairs of "and" and "or" operators -- call one % and the other %%.
3
votes
Distinguishing modulo (Euclidean division) from remainder
I support Bbrk24's answer, but to add on; whether you use % or %% for Euclidean modulo, you should consider what the target ...
Only top scored, non community-wiki answers of a minimum length are eligible