Compute the remainder and quotient of an integer division.
求 a 除以 b 的余数。
| Item | Formula / Note | Source / Standard |
|---|---|---|
| Modulo operation | a mod b = a - b · floor(a/b) | Knuth DE, The Art of Computer Programming, Vol. 1, §1.2.4 |
| Division with remainder | a = b · q + r with 0 <= r < |b| | Knuth DE, The Art of Computer Programming, Vol. 1, §1.2.4 |
| Congruence | a ≡ b (mod m) means m divides a - b | Gauss CF, Disquisitiones Arithmeticae (1801) |
| Negative operand caveat | Languages differ on the sign of the result for negative operands | ISO/IEC 10967-1:2012, Language independent arithmetic |