Modulo Calculator
Find a nonnegative remainder for a signed integer and a positive integer modulus.
Formula
q = floor(a/m); r = a − m×q; 0 ≤ r < m
Floor quotient q ≈ floor((-17)÷(5)) · Remainder r ≈ (-17)-(5)×(-4)
How to use
- Enter a signed integer a.
- Enter a positive integer modulus m.
- Read the remainder and floor quotient.
Examples
- 17 mod 5 = 2; −17 mod 5 = 3.
Frequently asked questions
Can the dividend be negative?
Yes. −17 modulo 5 is 3 because −17 = 5×(−4)+3.
Why can programming languages disagree?
Some use a remainder with the dividend’s sign. This tool uses floor division and a positive modulus.
Can the modulus be zero?
No. It must be a positive integer.
Sources
Updated: