For an integer, a, or a method to find the remainder of the operation is divided into the following two steps:
1. Seeking integer quotient: c=a/b
2. Calculating the modulus or remainder: r=a-(c*b)
Modulo operation and redundancy operation are different in the first step.
The remainder operation discards the decimal place in the 0 direction of the quotient value
The modulo operation discards the decimal place in the negative infinity direction of the quotient value for example:
4/(-3) approximately equals-1.3 the quotient value discards the decimal bit to 0 in the time of the remainder operation. 1
The quotient value discards the decimal bit to 2 in the negative infinity direction during the modulo operation
So
4rem ( -3) =1 4mod (-3) =-2
Take the remainder, follow as far as possible to let the business to 0 close to the principle of modulo, follow as far as possible to the negative infinity close to the principle of the symbol, the two will not conflict.
For example, 7/3=2.3,
Produced two quotient of 2 and 3 7=3*2+1 or 7=3*3+ (-2).
So, 7rem3=1,7mod3=1.
Symbols are not the same, they create conflicts.
For example, 7/(-3) =-2.3,
Generated two quotient-2 and-3 7 = (-3) * (-2) +1 or 7 = (-3) * (-3) + (-2).
Therefore, 7rem ( -3) =1,7mod (-3) = (-2)
Usually, the modulo operation is called the remainder operation,
They return the result as a remainder. The only difference between REM (take-up) and mod (modulo) is:
When x and Y are the same sign, two function results are equivalent;
When the symbols for x and y are not the same, the REM function results in the same symbol as x, while mod and y are the same.