Skip to main content
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 ...
kaya3's user avatar
  • 20.8k
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, ...
Jules's user avatar
  • 211
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 ...
IMSoP's user avatar
  • 2,727
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 %%.
Bbrk24's user avatar
  • 9,407
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 ...
SectorCorruptor's user avatar

Only top scored, non community-wiki answers of a minimum length are eligible