Ver código fonte

Merge branch 'debug' of http://8.136.199.33:3000/eta_server/eta_index_lib into debug

xyxie 2 meses atrás
pai
commit
2c066bdb71
2 arquivos alterados com 7 adições e 0 exclusões
  1. 1 0
      models/base_from_calculate.go
  2. 6 0
      services/math_engine.go

+ 1 - 0
models/base_from_calculate.go

@@ -595,6 +595,7 @@ func ReplaceFormula(edbInfoIdArr []*EdbInfo, valArr, valArrMax map[int]float64,
 	formulaStr = strings.Replace(formulaStr, "CBRT", "cbrt", -1)
 	formulaStr = strings.Replace(formulaStr, "NOERR", "noerr", -1)
 	formulaStr = strings.Replace(formulaStr, "DOUBLE", "double", -1)
+	formulaStr = strings.Replace(formulaStr, "POW", "pow", -1)
 	if replaceCount == len(formulaMap) {
 		return formulaStr
 	} else {

+ 6 - 0
services/math_engine.go

@@ -15,4 +15,10 @@ func init() {
 	engine.RegFunction("ln", 1, func(expr ...engine.ExprAST) float64 {
 		return math.Log(engine.ExprASTResult(expr[0]))
 	})
+
+	engine.RegFunction("pow", 2, func(expr ...engine.ExprAST) float64 {
+		x := engine.ExprASTResult(expr[0])
+		y := engine.ExprASTResult(expr[1])
+		return math.Pow(x, y)
+	})
 }