math_engine.go 415 B

123456789101112131415161718
  1. package services
  2. import (
  3. "github.com/dengsgo/math-engine/engine"
  4. "math"
  5. )
  6. func init() {
  7. engine.RegFunction("log", 2, func(expr ...engine.ExprAST) float64 {
  8. base := math.Log(engine.ExprASTResult(expr[0]))
  9. number := math.Log(engine.ExprASTResult(expr[1]))
  10. return number / base
  11. })
  12. engine.RegFunction("ln", 1, func(expr ...engine.ExprAST) float64 {
  13. return math.Log(engine.ExprASTResult(expr[0]))
  14. })
  15. }