title: Make a function similar to modulo that also works with negative numbers
body: <p>I need to make a function <code>f(a,b)</code> that will give the following results:</p>
  <pre><code>f(0, 3) = 0
  f(1, 3) = 1
  f(2, 3) = 2
  f(3, 3) = 0
  f(4, 3) = 1... (this works exactly like a%b)
  </code></pre>
  <p>However it should also follow this pattern for negative numbers:</p>
  <pre><code>f(-4, 3) = 2
  f(-3, 3) = 0
  f(-2, 3) = 1
  f(-1, 3) = 2
  f( 0, 3) = 0
  </code></pre>
  <p>I currently found this solution:</p>
  <pre><code>x = a % b
  return a &lt; 0 &amp;&amp; mod != 0 ? mod + b : mod;
  </code></pre>
  <p>However this feels way too complicated and slow for what I'm trying to achieve. Isn't there a simpler way to generate a sequence similar to modulo that continues for negative values?</p>