ToolBark
Math

Modulo Calculator

Compute a mod n — negatives handled correctly, every convention shown

Inputs

Convention

Result

-13 mod 5 =

2

All conventions at a glance

ConventionQuotient (q)Remainder (r)
Floored-32
Truncated-2-3
Euclidean2

Verify: a = q × n + r

Floored: -3 × 5 + 2 = -13

Truncated: -2 × 5 + -3 = -13

Quick Examples

About

The modulo operation finds the remainder after dividing one number by another, but the result differs depending on how negative numbers are handled. This free modulo calculator computes a mod n using three conventions: floored (Python, Ruby), truncated (JavaScript, C, Java), and Euclidean (always non-negative). Enter any integers — positive or negative — and get instant, verified results across all conventions.

FAQ
Why does −13 mod 5 give different answers in Python vs JavaScript?+

Python uses floored division, so the remainder always has the same sign as the divisor (n). JavaScript uses truncated division, so the remainder takes the sign of the dividend (a). For −13 mod 5: Python gives 2, while JavaScript gives −3.

Which modulo convention should I use?+

Use floored (Python-style) for most mathematical work and clock/cyclic arithmetic since the result is always in [0, n−1] when n > 0. Use truncated when matching JavaScript, C, or Java behavior. Use Euclidean when you need a guaranteed non-negative result regardless of the signs of both inputs.

Does modulo work on non-integers?+

Yes — the same conventions apply to decimal numbers. For example, 5.5 mod 2.5 gives 0.5. This calculator supports any finite real number for both the dividend and modulus.

What is the Euclidean modulo?+

The Euclidean remainder is always non-negative. It is computed as a % |n|, then if the result is negative, |n| is added. This ensures the result lies in the range [0, |n|) regardless of the signs of a or n, satisfying the property that a = q × |n| + r with r ≥ 0.

Related tools