September 07, 2012
On 8/11/2012 11:54 AM, Thiez wrote:
> A few extra instructions (a CMOV followed by ADD should suffice, yes?) seems
> like a small price to pay if it can prevent bugs. Why hasn't the Python-modulo
> been made the default back when D was designed? The ever-so-slightly more
> efficient C-modulo could be provided in a library. Of course it's way too late
> to change it now...


Because then C code translated to D will have subtle, silent and unexpected bugs.
September 07, 2012
Walter Bright:

> Because then C code translated to D will have subtle, silent and unexpected bugs.

I agree. So the solution is to introduce a new Phobos function or new built-in operator that works more correctly with negative numbers too.

A new Phobos function named mod() is a very simple solution.

While a new infix operator has the advantage of being more natural to use, this allows programmers to better remember to use it instead of the C %, so the maybe a built-in operator avoids some bugs compared to the function.

Bye,
bearophile
1 2 3
Next ›   Last »