Implement modulo operation

This commit is contained in:
Elara 2023-10-30 16:59:37 -07:00
parent 41adf9ce51
commit dce4ee2e8f

View File

@ -131,6 +131,14 @@ func (t *Template) performOp(a, b reflect.Value, op ast.Op) any {
case reflect.Float64, reflect.Float32: case reflect.Float64, reflect.Float32:
return a.Float() / b.Float() return a.Float() / b.Float()
} }
case "%":
switch a.Kind() {
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
return a.Int() % b.Int()
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64, reflect.Uintptr:
return a.Uint() % b.Uint()
case reflect.Float64, reflect.Float32:
return a.Float() % b.Float()
case "in": case "in":
if a.Kind() == reflect.String && b.Kind() == reflect.String { if a.Kind() == reflect.String && b.Kind() == reflect.String {
return strings.Contains(b.String(), a.String()) return strings.Contains(b.String(), a.String())