Forráskód Böngészése

新增自定义函数

hongze 7 hónapja
szülő
commit
a7a2759d52
1 módosított fájl, 18 hozzáadás és 0 törlés
  1. 18 0
      services/math_engine.go

+ 18 - 0
services/math_engine.go

@@ -0,0 +1,18 @@
+package services
+
+import (
+	"github.com/dengsgo/math-engine/engine"
+	"math"
+)
+
+func init() {
+	engine.RegFunction("log", 2, func(expr ...engine.ExprAST) float64 {
+		base := math.Log(engine.ExprASTResult(expr[0]))
+		number := math.Log(engine.ExprASTResult(expr[1]))
+		return number / base
+	})
+
+	engine.RegFunction("ln", 1, func(expr ...engine.ExprAST) float64 {
+		return math.Log(engine.ExprASTResult(expr[0]))
+	})
+}