math.Mod
Returns the modulus of two integers.
- Syntax
- math.Mod VALUE1 VALUE2
- Returns
- int64
- Alias
- mod
Usage
The math.Mod function returns the modulus of two integers, which is the remainder after dividing VALUE1 by VALUE2. The result has the same sign as VALUE1. The function converts both values to integers before dividing, removing any fractional part, and throws an error if VALUE2 is 0.
Examples
{{ math.Mod 15 3 }} → 0
{{ math.Mod 15 4 }} → 3With a negative number:
{{ math.Mod -15 4 }} → -3Last updated:
October 21, 2026
:
content: Apply style guide to math functions (658ef2b60)
Improve this page