>> Int a = -5; Int b = -2;
> For integer operands, % is designed to maintain the identity:
[quoted text clipped - 3 lines]
>
> ( (-5)/(-2) ) * (-2) + (-1) is -5.
A nitpick question: Is the division ( (8)/(3) ) also 2 in Java?
If so, why is this be called "rounding"?
Lee Weiner - 05 Nov 2006 17:12 GMT
>>> Int a = -5; Int b = -2;
>> For integer operands, % is designed to maintain the identity:
[quoted text clipped - 6 lines]
>A nitpick question: Is the division ( (8)/(3) ) also 2 in Java?
>If so, why is this be called "rounding"?
It is not called rounding. It is called integer division.
Patricia Shanahan - 05 Nov 2006 17:46 GMT
>>> Int a = -5; Int b = -2;
>> For integer operands, % is designed to maintain the identity:
[quoted text clipped - 6 lines]
> A nitpick question: Is the division ( (8)/(3) ) also 2 in Java?
> If so, why is this be called "rounding"?
I usually use "rounding" in the sense in which it is used in e.g. the
IEEE 754 standard, to mean modifying the infinitely precise result of a
calculation to fit in the destination's format.
In that usage, it includes rounding directed rounding, such as rounding
towards zero, as well as the various flavors of round to nearest. Some
people use "truncation" when the rounding is towards either zero or
negative infinity.
Patricia
> > Int a = -5; Int b = -2;
> > System.out.println(a % b); // -1
[quoted text clipped - 15 lines]
>
> Patricia
nice explanation!