Why does the modulus of a negative number N where abs(N) is smaller than the divisor D become a small positive number instead of -N.
Say we use -3 % 5 as an example, why is this 2 as opposed to -3?
Why does the modulus of a negative number N where abs(N) is smaller than the divisor D become a small positive number instead of -N.
Say we use -3 % 5 as an example, why is this 2 as opposed to -3?
At first -3%5 is not equal to 2. It is equal to -3. Additionally the -3( 5*0 + (-3)) is equal to 9. You entire calculation is wrong unfortunately. Modulus calculates with absolute value first and then make sign changes. Such as; -7%5=-2 in c++. Modulus divide 7 to 5 first then checks the sign and changes the sign negative or positive.