Should % ever "overflow"?

Guillaume Boucher via Digitalmars-d digitalmars-d at puremagic.com
Sat Jun 25 17:54:04 PDT 2016


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.



More information about the Digitalmars-d mailing list