The C # compiler does the right thing according to the C # specification, which states that for integers:
The result of x % y
is the value generated by x β (x / y) * y
.
Note that (x/y)
always rounds to zero .
For details on how the remainder is calculated for binary and decimal floating point numbers, see section 7.8.3 of the specification.
Whether this will be the βright answerβ for you depends on how you view the stop operation. The rest should satisfy an identity that:
dividend = quotient * divisor + remainder
I say clear -2% 360 = -2. What for? First ask yourself what a factor is. How many times does 360 go -2? Clearly zero time! 360 doesn't go at -2 at all. If the factor is zero, then the remainder must be -2 to satisfy the identity. It would be strange to say that 360 goes -2 a total of -1 times, with a remainder of 358, do not you think?
source share