Add Mod operation

This commit is contained in:
Anant Jain
2025-05-14 22:38:13 -07:00
parent bd5cacd14a
commit a5b0664b9c
2 changed files with 13 additions and 1 deletions

View File

@@ -414,6 +414,14 @@ func customAPIDoMathOp[T int | float64](a, b T, op string) T {
return 0
}
return a / b
case "mod":
ai, bi := any(a), any(b)
aint, aok := ai.(int)
bint, bok := bi.(int)
if aok && bok && bint != 0 {
return T(aint % bint)
}
return 0
}
return 0
}
@@ -479,6 +487,9 @@ var customAPITemplateFuncs = func() template.FuncMap {
"div": func(a, b any) any {
return doMathOpWithAny(a, b, "div")
},
"mod": func(a, b int) any {
return doMathOpWithAny(a, b, "mod")
},
"now": func() time.Time {
return time.Now()
},