Merge pull request #661 from anant-j/dev

Add Mod operation
This commit is contained in:
Svilen Markov authored and GitHub committed 2025-05-16 17:33:58 +01:00
commit 9bbf73db97
2 files changed
+13 -1

No files matched your search

+11
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()
},