title: Is there an expression using modulo to do backwards wrap-around ("reverse overflow")?
body: <p>For any whole number input <em>W</em> restricted by the range <em>R</em> = [<em>x</em>,<em>y</em>], the "overflow," for lack of a better term, of <em>W</em> over <em>R</em> is <code>W % (y-x+1) + x</code>. This causes it wrap back around if <em>W</em> exceeds <em>y</em>.</p>
  
  <p>As an example of this principle, suppose we iterate over a calendar's months:</p>
  
  <pre><code>int this_month = 5;
  int next_month = (this_month + 1) % 12;
  </code></pre>
  
  <p>where both integers will be between 0 and 11, inclusive. Thus, the expression above "clamps" the integer to the range <em>R</em> = [0,11]. This approach of using an expression is simple, elegant, and advantageous as it <strong><em>omits branching</em></strong>.</p>
  
  <p>Now, what if we want to do the same thing, but backwards? The following expression works:</p>
  
  <pre><code>int last_month = ((this_month - 1) % 12 + 12) % 12;
  </code></pre>
  
  <p>but it's abstruse. How can it be beautified?</p>
  
  <hr>
  
  <p><strong>tl;dr</strong> - Can the expression <code>((x-1) % k + k) % k</code> be simplified further?</p>
  
  <p><em>Note: C++ tag specified because other languages handle negative operands for the modulo operator differently.</em></p>