Mathematics · pattern A, Numeric fields
Enter a value and a modulus for the remainder, with the mathematically non-negative version shown alongside the one most programming languages return.
a mod m is the remainder after dividing a by m
For negative a, most languages return a negative remainder while mathematics takes the non-negative one. Both are shown below.
-2
Modulo wraps numbers into a fixed range, which is what makes clocks, calendars, hash tables and cyclic buffers work. The trap is negatives: −17 mod 5 is 3 in mathematics and −2 in C, Java and JavaScript, and code that indexes an array with the result crashes on the difference.
If the number is not the part you are stuck on, that is what the service is for — a specialist who explains the working, not just the answer.
Arithmetic runs in double-precision floating point, so results beyond about fifteen significant figures are not exact. Where a question wants an exact fraction or surd, keep the exact form rather than a decimal.