Modulo Calculator

The modulo operation returns the remainder of a division. For positive numbers everyone agrees: 17 mod 5 = 2. But for negative numbers, languages and mathematicians diverge. The mathematical convention defines a mod b so the result is always in the range [0, |b|) — so -7 mod 3 = 2. The C/Go/JavaScript convention uses truncated division, so the remainder takes the sign of the dividend — meaning -7 % 3 = -1. This calculator shows both so you can pick the one your domain expects. It also supports floating-point moduli (used in angle wrapping, clock arithmetic, and signal processing) and explains each step of the calculation.

star 4.8
auto_awesome AI
New

percent a mod b

The number being divided. Integers or decimals, positive or negative.

The modulus. Must be non-zero.

analytics Result

Modulo (math, floored)
2
Always in range [0, |b|)
Remainder (C-style, truncated) 2

Sign follows dividend. Matches C, C++, Go, Java, JavaScript (%).

Quotient (floor)
3
Quotient (trunc)
3
Step by step

    tips_and_updates Tips

    • Use math modulo (floored) for modular arithmetic, hashing, and angle wrapping
    • Use C-style modulo (truncated) when matching behavior of C, C++, Go, Java, or JavaScript
    • For positive a and b the two conventions agree, so the distinction only matters with negatives
    • Modulo by zero is undefined — the divisor must be non-zero
    • Python's % operator uses math (floored) modulo: -7 % 3 = 2

    The Formula

    Math modulo uses floor division so the remainder is always 0 <= r < |b|. C-style modulo uses truncated division so the remainder has the same sign as the dividend.

    r = a - b * q, where q = floor(a/b) (math) or trunc(a/b) (C-style)

    lightbulb Variables Explained

    • a Dividend (the number being divided)
    • b Divisor (the modulus)
    • q Quotient (floored or truncated)
    • r Remainder / modulo result

    tips_and_updates Pro Tips

    1

    Use math modulo (floored) for modular arithmetic, hashing, and angle wrapping

    2

    Use C-style modulo (truncated) when matching behavior of C, C++, Go, Java, or JavaScript

    3

    For positive a and b the two conventions agree, so the distinction only matters with negatives

    4

    Modulo by zero is undefined — the divisor must be non-zero

    5

    Python's % operator uses math (floored) modulo: -7 % 3 = 2

    Frequently Asked Questions

    sell

    Tags

    verified

    Data sourced from trusted institutions

    All formulas verified against official standards.