Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion docs/math.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
22 changes: 22 additions & 0 deletions numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down