1.<br>The % operator, just like in C/C++, calculates the remainder, but it doesn't handle negative numbers properly.  It's not a mod operator, even though sometimes it's called that.<br><br>  assert(-6 %  20 == -6);<br>
  assert( 6 % -20 ==  6);<br>  assert(-6 % -20 == -6);<br><br>I use my own mod function whenever I need to handle negative numbers.  It looks like this:<br><br>pure T mod(T)(T n, T d) if(isIntegral!(T)){<br>  T r = n % d;<br>
  return sgn(r) == -(sgn(d)) ? r + d : r;<br>}<br><br>  assert(mod(-6,  20) ==  14);<br>  assert(mod( 6, -20) == -14);<br>  assert(mod(-6, -20) == -6);<br><br>I'm hoping to see something like the above mod function in Phobos someday.  And perhapse a 'rem' or 'remainder' function that's a wrapper for the % operator, just to stay consistent.<br>
<br>2.<br>With the above, the math.fmod then would have to be renamed to 'frem' because, just like the % for integrals, it doesn't handle negative numbers properly only calculates the remainder.<br><br>  assert(fmod(-6,  20) == -6);<br>
  assert(fmod( 6, -20) ==  6);<br>  assert(fmod(-6, -20) == -6);<br><br>I'm not so sure why we have '<span class="ddoc_psymbol">re­main­der` and `</span><a name="remquo"></a><span class="ddoc_psymbol">remquo` in std.math when there is 'fmod`, though.<br>
<br>What do you guys think?<br></span>