Should % ever "overflow"?

Timon Gehr via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 25 18:36:16 PDT 2016


On 26.06.2016 02:54, Guillaume Boucher wrote:
> On Friday, 24 June 2016 at 20:43:38 UTC, deadalnix wrote:
>> Most reasonable is
>>
>> numerator = quotient * divisor + remainder
>>
>> Which means it can be negative.
>
> Depends on the definition.
>
> If division truncates towards negative infinity, the remainder will
> always be nonegative (in case of a positive divisor).
>
> I personally find rounding towards negative infinity the most practical;
> every time I used modulo, I wanted the result to be in the range [0,
> divisor).  Python does it this way and I find it very convenient.
>

I agree, but unfortunately signed integer division in D follows C's 
convention.


More information about the Digitalmars-d mailing list