I previously incorrectly thought that the %
operator returned the remainder and the mod
operator returned the modulus (the remainder and modulus are the same when the operands are both positive or both negative but differ when one operand is positive and the other is negative. Compare Raket's remainder and modulo functions).
However, that's not correct at all – both %
and mod
return the modulus; neither return the remainder. In fact, it looks like mod
will always return exactly the same value as %
would have, if called with the same arguments. As far as I can tell, the only difference is that %
can be called with non-integer arguments, whereas mod
throws an exception if called with anything other than Int:D
or int
.
So, what's the point of mod
? Is there some performance gain from using it (maybe by saving the optimizer some specialization work?) or is there some other difference I'm missing?