Modulo of Negative Numbers Calculator
Enter any dividend and divisor — including negatives — and compare the truncated, floored, and Euclidean remainders side by side with a full step-by-step breakdown of each convention.
Always ≥ 0 — the mathematically preferred convention
Truncated: quotient rounds toward zero
Truncated remainder (sign = sign of dividend a)
Floored: quotient rounds toward −∞
Floored remainder (sign = sign of divisor b)
Euclidean: remainder always ≥ 0
- 1
Absolute value of divisor
|5| = 5 - 2
Floor quotient
floor(-17 ÷ 5) = -4Using |b| ensures the remainder is always non-negative. - 3
Euclidean remainder
-17 − 5 × -4 = 3
How does this calculator work?
Modulo with negative numbers depends on the rounding convention. Truncated (JS/C/Java): remainder sign matches the dividend. Floored (Python/Ruby): remainder sign matches the divisor. Euclidean: remainder is always ≥ 0 (range [0, |b|)). All three agree when both inputs are positive.
Formula
How this is calculated
The three modulo conventions agree for positive inputs but diverge when a or b is negative — the difference lies in how the quotient is rounded before the remainder is extracted.
Truncated division rounds the quotient toward zero (trunc(a/b)), so the remainder rT = a − b·trunc(a/b) always carries the sign of the dividend a. This is the behaviour of % in C, C++, Java, JavaScript, Go and most compiled languages. Floored division rounds toward negative infinity (floor(a/b)), so rF = a − b·floor(a/b) carries the sign of the divisor b — this is Python's % and Ruby's % operator. Euclidean division forces the remainder to always be non-negative by using the absolute value of b for rounding: rE = a − |b|·floor(a/|b|), keeping 0 ≤ rE < |b| regardless of the signs of either operand.
For programming use, match the convention of your target language. For mathematical modular arithmetic (e.g. group theory, RSA, clock arithmetic) the Euclidean remainder is canonical because a non-negative remainder means a and a + k·|b| are always in the same congruence class without surprises.
Frequently asked questions
JavaScript uses truncated division (quotient = trunc(−17/5) = −3), giving −17 − 5×(−3) = −2. Python uses floored division (quotient = floor(−17/5) = −4), giving −17 − 5×(−4) = 3. The Euclidean remainder is also 3 in this case.
The Euclidean remainder (always non-negative) is the standard in number theory and modular arithmetic because it preserves the congruence relation cleanly. Use it whenever you write a ≡ b (mod n) in a mathematical context.
Yes. For a negative divisor the three conventions can produce three distinct remainders. The Euclidean convention uses |b| internally, so the remainder range is always [0, |b|) regardless of the sign of b.
Also known as
TG we-Calculate Editorial Team. (2026). Modulo of Negative Numbers Calculator [Online calculator]. TG we-Calculate. https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator
TG we-Calculate Editorial Team. "Modulo of Negative Numbers Calculator." TG we-Calculate. 2026. https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator.
TG we-Calculate Editorial Team, "Modulo of Negative Numbers Calculator," TG we-Calculate, 2026. [Online]. Available: https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator
@misc{wecalculate_modulo_of_negative_numbers_calculator, title = {Modulo of Negative Numbers Calculator}, author = {{TG we-Calculate Editorial Team}}, howpublished = {\url{https://we-calculate.com/calculator/modulo-of-negative-numbers-calculator}}, year = {2026}, note = {TG we-Calculate} }
Did this calculator help you?
