1
0

merge: 合并代码20241211

This commit is contained in:
TsMask
2024-12-11 16:15:13 +08:00
parent aedea2ce2d
commit 1fa9442c1f
43 changed files with 885 additions and 479 deletions

View File

@@ -5,6 +5,7 @@ import (
"go/ast"
"go/parser"
"go/token"
"math"
"regexp"
"strconv"
"strings"
@@ -29,6 +30,9 @@ func CalcExpr(expr string, paramValues map[string]any) (float64, error) {
// expression to evaluate
result, err := evalExpr(expr)
if math.IsNaN(result) {
return 0.0, err
}
return result, err
}
@@ -87,6 +91,10 @@ func evalNode(node ast.Node) (float64, error) {
case token.MUL:
result = left * right
case token.QUO:
if right == 0 {
return math.NaN(), fmt.Errorf("divisor cannot be zero")
}
result = left / right
}
case *ast.BasicLit: