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.

All functions