Negative Modulo Calculator

Handle negative dividends and divisors with robust, standards‑based modular arithmetic for consistency. Switch conventions, see stepped derivations, and verify congruence class mappings across examples. Batch evaluate lists, normalize residues, and export cleanly formatted tables quickly. Understand signs, avoid confusion, and compute correct remainders everywhere.

Inputs


Result
r = 0 q = 0
Congruence
a ≡ r (mod m)

          

Downloads

Downloads include the results table beneath. Add rows first.

Results Table

# a m Convention q r Congruence

Formula Used

All conventions satisfy the integer division identity a = q·m + r. The conventions differ in how q is chosen, which controls the sign/range of r.

  • Euclidean: uses modulus |m|, chooses q = ⌊a/|m|⌋, giving 0 ≤ r < |m|. Implementation trick: r = ((a % |m|) + |m|) % |m|.
  • Truncated toward zero: chooses q = trunc(a/m) (e.g., intdiv), so r may be negative when a is negative.
  • Floor division remainder: chooses q = ⌊a/m⌋, so r can be non‑negative or have the sign of m depending on inputs.

For modular arithmetic in number theory, the Euclidean convention is standard: report r ∈ {0,1,…,|m|−1} and write a ≡ r (mod |m|).

How to Use This Calculator

  1. Enter an integer dividend a and a non‑zero modulus m.
  2. Select a convention: Euclidean (recommended), Truncated, or Floor.
  3. Click Calculate to see q, r, steps, and congruence.
  4. Use Add to table to accumulate multiple calculations.
  5. Export the table as CSV or as a PDF document.

Tip: For negative moduli, Euclidean mode automatically uses |m| and reports a non‑negative residue.

Example Data Table

Click any row to load its a, m, and convention into the form.

amConventionqrCongruence
-135Euclidean-32-13 ≡ 2 (mod 5)
-135Truncated-2-3-13 ≡ -3 (mod 5)
-135Floor-32-13 ≡ 2 (mod 5)
-73Euclidean-32-7 ≡ 2 (mod 3)
-73Truncated-2-1-7 ≡ -1 (mod 3)
-7-3Euclidean-32-7 ≡ 2 (mod 3)
13-5Truncated-2313 ≡ 3 (mod -5)
135Euclidean2313 ≡ 3 (mod 5)

Why Different Modulo Conventions Exist

All conventions satisfy a = q·m + r, but each chooses q differently, changing the reported r. This matters when a or m is negative.

  • Number Theory: prefers non‑negative residues to represent congruence classes cleanly.
  • Systems Programming: truncated division matches legacy machine instructions and is fast.
  • Mathematical Analysis: floor division aligns with inequalities and interval reasoning.

When doing modular arithmetic proofs or cryptography, use the Euclidean convention so residues lie in [0, |m| − 1].

Mapping Between Conventions

Given any remainder r_x from a chosen convention and non‑zero m, the Euclidean residue is:

r_e = ((r_x % |m|) + |m|) % |m|

Direct formulas for each convention:

  • Truncated: q_t = trunc(a/m), r_t = a − q_t·m.
  • Floor: q_f = ⌊a/m⌋, r_f = a − q_f·m.
  • Euclidean: q_e = ⌊a/|m|⌋, r_e = a − q_e·|m|, with 0 ≤ r_e < |m|.

Example mapping with a = −13, m = 5:

ConventionqrNote
Truncatedq_t = −2r_t = −3May return negative remainder.
Floorq_f = −3r_f = 2Remainder non‑negative for m > 0.
Euclideanq_e = −3r_e = 2Residue in [0,4].

From r_t = −3, compute r_e = ((−3 % 5)+5)%5 = 2.

Common Pitfalls and Quick Checks

  • Never use m = 0; the modulus must be non‑zero.
  • For Euclidean residues, always verify 0 ≤ r < |m|.
  • Confirm the identity a = q·m + r numerically after each computation.
  • Mixing conventions can confuse tests; normalize to Euclidean for comparisons.
  • Negative m? Use |m| when reporting residues in Euclidean mode.

If portability matters, store normalized Euclidean residues and the original m alongside results.

Related Calculators

Proportion and Ratio Calculatorsquare root calculator with stepsnegative square root calculatorfraction square root calculatorsquare root division calculatordecimal to square root calculatorderivative of square root calculatorharmonic mean calculatorbinomial distribution mean calculatordiscrete random variable mean calculator

Important Note: All the Calculators listed in this site are for educational purpose only and we do not guarentee the accuracy of results. Please do consult with other sources as well.