Should % ever "overflow"?

jmh530 via Digitalmars-d digitalmars-d at puremagic.com
Fri Jun 24 14:01:01 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.

Example:

void main()
{
	int x1 = 2;
	int x2 = -2;
	uint x3 = 2;
	
	assert(-7 % x1 == -1);
	assert(-7 % x2 == -1);
	assert(-7 % x3 == -1); //fails
}




More information about the Digitalmars-d mailing list