Modulo Calculator
Calculate the remainder of a division - clearly explains how negative operands are handled, since modulo behavior differs across languages.
Enter two numbers - this tool calculates the remainder and explains the result, especially for negative operands where behavior varies by language.
When both operands are positive, these are identical. With a negative dividend, JavaScript's % (and most C-family languages) returns a result with the same sign as the dividend - the "true" mathematical modulo (as used in Python) always returns a result with the same sign as the divisor. Both are shown so you can see the difference clearly.
JavaScript's % operator (which this tool uses) returns a result with the same sign as the dividend - some languages (like Python) instead return a result with the same sign as the divisor. Both are documented below.
Modulo vs. Remainder - Why Negatives Matter
For positive numbers, "modulo" and "remainder" always agree. For negative operands, they can differ: JavaScript, C, and Java's % operator gives a result with the same sign as the dividend (true "remainder" semantics), while Python's % gives a result with the same sign as the divisor (true "modulo" semantics).
How to Use It
- Enter a dividend and a divisor.
- View the result using JavaScript/remainder semantics, alongside the Python-style modulo result for comparison when they'd differ.
Handling Division by Zero
Division/modulo by zero is mathematically undefined - this tool reports that clearly rather than returning a misleading NaN with no explanation.