diff --git a/docs/math.md b/docs/math.md index b08d0a2f..0d19e1e0 100644 --- a/docs/math.md +++ b/docs/math.md @@ -24,7 +24,14 @@ Perform integer division with `div` ## mod -Modulo with `mod` +Perform modulo with `mod`. The result is the remainder of dividing the first +argument by the second. + +``` +mod 10 3 +``` + +The above will return `1`, because `10 % 3 = 1`. ## mul diff --git a/numeric_test.go b/numeric_test.go index 1252cd73..44915c7f 100644 --- a/numeric_test.go +++ b/numeric_test.go @@ -249,6 +249,28 @@ func TestDivf(t *testing.T) { } } +func TestMod(t *testing.T) { + tpl := `{{ mod 10 3 }}` + if err := runt(tpl, `1`); err != nil { + t.Error(err) + } + + tpl = `{{ mod 10 2 }}` + if err := runt(tpl, `0`); err != nil { + t.Error(err) + } + + tpl = `{{ mod 10 10 }}` + if err := runt(tpl, `0`); err != nil { + t.Error(err) + } + + tpl = `{{ mod 7 3 }}` + if err := runt(tpl, `1`); err != nil { + t.Error(err) + } +} + func TestMul(t *testing.T) { tpl := `{{ 1 | mul "2" 3 "4"}}` if err := runt(tpl, `24`); err != nil {