title: What is this zero-invariant modulus function called?
body: <p>I've got some code that calculates a cyclic offset for a given integer, and I want it to calculate the cyclic-offset such that the function's output will not show any anomalous behavior as the input value transitions from positive to negative and back.</p>
  
  <p>Here's my current implementation, which appears to work correctly, AFAICT:</p>
  
  <pre><code> #include &lt;stdio.h&gt;
  
   unsigned int PositiveModulus(int value, unsigned int divisor)
   {
      if (value &lt; 0)
      {
         const int numCyclesToAdd = 1+((-value)/divisor);
         value += numCyclesToAdd*divisor;
      }
      return value%divisor;
   }
  
   // unit test
   int main(int argc, char ** argv)
   {
      for (int i=-10; i&lt;=10; i++) printf("%i -&gt; %u\n", i, PositiveModulus(i,5));
      return 0;
   }
  </code></pre>
  
  <p>... in particular, when I run the above, I get the following output, which demonstrates the behavior I want:</p>
  
  <pre><code> $ ./a.out
   -10 -&gt; 0
   -9 -&gt; 1
   -8 -&gt; 2
   -7 -&gt; 3
   -6 -&gt; 4
   -5 -&gt; 0
   -4 -&gt; 1
   -3 -&gt; 2
   -2 -&gt; 3
   -1 -&gt; 4   // note output transitions from 4 to 0 on these two
   0 -&gt; 0    // lines, just like every other iteration of the cycle
   1 -&gt; 1
   2 -&gt; 2
   3 -&gt; 3
   4 -&gt; 4
   5 -&gt; 0
   6 -&gt; 1
   7 -&gt; 2
   8 -&gt; 3
   9 -&gt; 4
   10 -&gt; 0
  </code></pre>
  
  <p>My question is, does this function have a well-known/official name?  (Searching for "positive modulus" returns some results, but the function described in those results doesn't seem to behave the same as the above code)</p>
  
  <p>... and a bonus question is:  Is the function shown above the best way to implement this behavior, or is there another approach that is more concise and/or mathematically correct?</p>