I think a lot of people do not know the difference between these two concepts, just in the translation of the LUA manual with the math.fmod of the two operations, by the way to explain it.
The difference between the modulus and the remainder is obtained.
Suppose to do modulo or remainder operations on a and b two integers. So the first step is to find the integer quotient C, A/b value, and the second step is to calculate the modulus or remainder: A-c * b. The difference between modulo and remainder is how to deal with A/b value.
In the modulo operation, the result of A/b is rounded in the direction of infinity, and the result of A/b is rounded to 0 in the remainder operation.
Therefore, the symbol of the result is consistent with B, and the sign of the result is consistent with a.
In Lua, 4% (-3) equals 2, which shows that the% Lua is a modulo operation rather than a remainder operation. 4/(-3) round to infinity Small to 2, then modulus 4-(-2 *-3) =-2.
Math.fmod (4,-3) is equal to 1 in Lua, so Fmod is a remainder operation rather than a modulo operation. 4/(-3) rounded to 1 in 0 direction, the remainder is 4-(-1 *-3) = 1.
It is easy to draw another conclusion: if the a,b are all positive integers, there is no difference between the modulus and the remainder.