mod

x % y

x mod y

mod(x, y)

Try it yourself:

See also:

Compute a mathematical modulus

mod(a, b) returns the remainder-like value of a modulo b operation. It is useful for cycles, wrapping indexes, clock arithmetic, and periodic patterns.

Example

mod(17, 5) is 2. Use rem when the remainder convention for signed values is what you need; the two can differ for negative inputs. floor helps explain the mathematical definition.

Caveats

The divisor must not be zero. Be explicit about negative-value conventions in indexing code, and use round only if input values must first become integers. For cyclic angles, combine mod with pi carefully.

Try Mod in Calcul.io

Start with one of the editable examples above, then replace its arguments with your own values. Keeping the function on a separate calculator line makes the input and result easy to compare. For a longer workflow, assign the result to a variable or reference that line in the next expression.

Check the shown signature before adding optional arguments, and use the related-function links to compare operations with similar purposes.

All functions