A few extra instructions (a CMOV followed by ADD should suffice, yes?) seems like a small price to pay if it can prevent bugs.

The price would really be quite insignificant since IDIV takes tens of cycles and the additional work needed to make module behave intuitively would be just a few cycles. 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.

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.

Reply via email to