Add "mod" function for modulo in templating

Signed-off-by: Knut Ahlers <knut@ahlers.me>
This commit is contained in:
Knut Ahlers 2022-07-15 19:25:05 +02:00
parent b0d9b5782f
commit bf9ec094bf
Signed by: luzifer
GPG key ID: 0066F03ED215AD7D

View file

@ -9,6 +9,7 @@ import (
func Register(args plugins.RegistrationArguments) error { func Register(args plugins.RegistrationArguments) error {
args.RegisterTemplateFunction("add", plugins.GenericTemplateFunctionGetter(add)) args.RegisterTemplateFunction("add", plugins.GenericTemplateFunctionGetter(add))
args.RegisterTemplateFunction("div", plugins.GenericTemplateFunctionGetter(div)) args.RegisterTemplateFunction("div", plugins.GenericTemplateFunctionGetter(div))
args.RegisterTemplateFunction("mod", plugins.GenericTemplateFunctionGetter(mod))
args.RegisterTemplateFunction("mul", plugins.GenericTemplateFunctionGetter(mul)) args.RegisterTemplateFunction("mul", plugins.GenericTemplateFunctionGetter(mul))
args.RegisterTemplateFunction("multiply", plugins.GenericTemplateFunctionGetter(mul)) // DEPRECATED args.RegisterTemplateFunction("multiply", plugins.GenericTemplateFunctionGetter(mul)) // DEPRECATED
args.RegisterTemplateFunction("pow", plugins.GenericTemplateFunctionGetter(math.Pow)) args.RegisterTemplateFunction("pow", plugins.GenericTemplateFunctionGetter(math.Pow))
@ -18,5 +19,6 @@ func Register(args plugins.RegistrationArguments) error {
func add(m1, m2 float64) float64 { return m1 + m2 } func add(m1, m2 float64) float64 { return m1 + m2 }
func div(m1, m2 float64) float64 { return m1 / m2 } func div(m1, m2 float64) float64 { return m1 / m2 }
func mod(m1, m2 int64) int64 { return m1 % m2 }
func mul(m1, m2 float64) float64 { return m1 * m2 } func mul(m1, m2 float64) float64 { return m1 * m2 }
func sub(m1, m2 float64) float64 { return m1 - m2 } func sub(m1, m2 float64) float64 { return m1 - m2 }