Besides, modulo of unsigned integers would
still work the same, so you could just use that when you cared about the
difference in performance. So the only situation where you couldn't
avoid performance penalty would be when you needed to calculate modulo
of signed integers and you actually wanted the current behavior. I think
that is a pretty rare situtation.
My implementation of py_mod:
int py_mod(int a, int b) {
return cast(uint)a % b;
}
So a simple cast from signed to unsigned does exactly what I need
(Prf_Jakob showed me that in IRC)
How much does a cast cost? I mean is that even an extra asm instruction?
Why hasn't the Python-modulo been made the default back when D was
designed?
Probably because this is one of the design goals of D: Where D code
looks the same as C code, have it either behave the same or issue an error.
Unfortunatly.