A few days ago, a little sister asked me to take the remainder and modulo What is the difference, I was the first reaction is that the two are the same, but say as little sister killed. I went a bit Baidu really not the same. Skull hurt, I had misled many people. So to help me and to help prevent my memory fraught
In the C language for integers a, b, the method or the modulo operation is the remainder operation:
The first step, find the integer quotient: c = a / b;
A second step of calculating modulus or remainder: r = a - c * b.
So what difference it? In fact, in the first step
Remainder calculation when the calculated value c, rounding towards zero;
Modulo arithmetic in calculating the value of c to - ∞ rounding direction.
The so-called rounding towards zero, that is, with a decimal point as a boundary, the fractional part is directly removed. The (Int) -1.324 = -1 (also called truncation method);
In contrast to - ∞ rounding direction, the final result is less than the true value. The (Int) -1.324 = -2; ( int data type cast here)
So we use modulo arithmetic percent. (I did not understand what use modulo arithmetic)