Modulo Calculator

Calculate a mod b and compare mathematical modulo with the JavaScript remainder operator.

Category: Calculators

When to use?

Use it to find remainders, compare negative modulo behavior, build cyclic indexes, or reason about date and weekday calculations.

How to use

  • Enter dividend a and divisor b.
  • Review the mathematical modulo result.
  • Compare it with the JavaScript % remainder result.

Input Explanation

Enter integers for a and b. The divisor b cannot be 0. Negative values are supported.

Calculation Basis

Mathematical modulo is normalized against |b| so it is non-negative. JavaScript % uses a % b directly and keeps the sign of the dividend.

Usage Examples

  • Cyclic indexes - Wrap list or game indexes back into a fixed range.
  • Programming checks - See why negative remainders differ between math notation and code.

Examples

  • 13 mod 5 = 3 with quotient 2
  • -13 mod 5 = 2 mathematically, while JavaScript % returns -3
  • Use value mod 7 for weekday or cyclic index calculations

FAQ

Why are there two results?

Mathematical modulo and programming remainder often differ for negative dividends. Showing both avoids mistakes.

Can b be negative?

The input allows negative values, but for most practical modulo work use a positive divisor.

Related Tools

  • LCM Calculator - Calculate the least common multiple of two or more positive integers.
  • GCD Calculator - Calculate the greatest common divisor of two or more positive integers using the Euclidean algorithm.
  • Prime Number Checker - Check whether a natural number is prime and show its prime factorization when it is composite.
  • Percentage Calculator - Find what percentage a part is of a whole, or calculate a percentage of a value.
  • Discount Calculator - Enter the original price and discount rate to find the final price and the amount saved.
  • Ratio Calculator - Simplify the ratio of two values, or solve for the unknown in a proportion.