Richard F.L.R.Snashall wrote:
> Patricia Shanahan wrote:
>> gk wrote:
>>> Int a = -5; Int b = -2;
>> For integer operands, % is designed to maintain the identity:
>> (a/b)*b+(a%b) is equal to a.
>>
>> Java integer division rounds towards zero, so -5/-2 is 2.
>>
>> ( (-5)/(-2) ) * (-2) + (-1) is -5.
>
> A nitpick question: Is the division ( (
/(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