Compute the remainder when one integer is divided by another — the mathematical modulo operation, not just truncated division residue in floating-point contexts.
Operation
For integers a (dividend) and b (divisor):
result = a mod b
The implementation uses JavaScript’s % operator on validated finite numbers. Examples: 17 mod 5 → 2, -7 mod 3 → -2 (JavaScript preserves the dividend’s sign).
When to use it
Verify hash buckets, cyclic buffer indices, checksum intermediate steps, competitive-programming exercises, or classroom demonstrations of divisibility and congruence.
Limitations
Division by zero is rejected with an error. Non-integer or non-finite inputs are invalid. Sign behavior follows ECMAScript rules, which differ from the strictly non-negative modulus definition used in some cryptography texts (where the result is always 0 … b−1).
Note on negative dividends
If you need the mathematical convention where the remainder is always non-negative, adjust manually: ((a % b) + b) % b.