GithubHelp home page GithubHelp logo

dengsgo / math-engine Goto Github PK

View Code? Open in Web Editor NEW
309.0 309.0 78.0 64 KB

Mathematical expression parsing and calculation engine library. 数学表达式解析计算引擎库

License: Apache License 2.0

Go 100.00%
ast engine expression go lib library math mathematical vendor

math-engine's People

Contributors

dengsgo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

math-engine's Issues

1-- panic

input /> 1--
runtime: goroutine stack exceeds 1000000000-byte limit
fatal error: stack overflow

runtime stack:
runtime.throw(0x10d97b0, 0xe)
	/usr/local/go/src/runtime/panic.go:617 +0x72
runtime.newstack()
	/usr/local/go/src/runtime/stack.go:1041 +0x6f0
runtime.morestack()
	/usr/local/go/src/runtime/asm_amd64.s:429 +0x8f

goroutine 1 [running]:
github.com/dengsgo/math-engine/engine.(*AST).parsePrimary(0xc043fffdb0, 0x0, 0x0)
	/Users/admin/go/pkg/mod/github.com/dengsgo/[email protected]/engine/ast.go:164 +0x85c fp=0xc0240003e8 sp=0xc0240003e0 pc=0x109ef4c
github.com/dengsgo/math-engine/engine.(*AST).parsePrimary(0xc043fffdb0, 0x0, 0x0)

公式中的非法内容如何自动清除?

不知道是否已经提供了这种功能,我的公式,里面会含有一些不可解析的字符,比如
100*100米/扎=10000
这是我希望的结果,这里的 米/扎 显然是无法解析的。
这只是个例子,可能还会有 100kg/桶 等等诸如此类的。
有没有这样的功能,就是可以把这种无法运算的内容自动清除掉?

自定义函数不能注销

1、自定义函数只能注册,不能注销
2、自定义函数可不可以加一个绑定自定义参数(不是把参数写在公式里),因为自定义函数有些可能需要传一些对象,按目前的设计,要么把对像做成全局变量,要么就是用unsafe pointer,

Proposal: Please start using Semantic Versioning

I found that this project already supports Go modules. But sadly, the [tags](https://github.com https://github.com/dengsgo/math-engine/tags) doesn't follow Semantic Versioning, which means that all tags of this project will be ignored by Go modules and replaced by pseudo-versions, go get acts weirdly when tags are not in that form. It would be great to have the tagged release be named in the format vX.X.X format so that go mod can read it.

	github.com/dengsgo/math-engine v0.0.0-20200627074419-8918d8f8ea02

Else the mod file shows something like github.com/dengsgo/math-engine v0.0.0-20200627074419-8918d8f8ea02 which is not very readable and difficult to upgrade. It’s hard to verify which version is in use. This is not conducive to version control.

So, I propose this project to follow Semantic Versioning in future versions. For example, v1.0.1, v2.0.0, v3.1.0-alpha, v3.1.0-beta.2etc, so that other project can use tag in go.mod.

增加注册自定义函数的能力

可以把常用的函数注册到引擎中,然后就能像内置函数一样在输入的数学表达式中使用。

e.g

  engine.RegFunction("double", 1, func(expr ...engine.ExprAST) float64 {
    return engine.ExprASTResult(expr[0]) * 2
  })

然后就可以在输入的表达式中使用这个函数 double:

exp := "double(6) + 2"
r, err := engine.ParseAndExec("double(6) + 2")
if err != nil {
  panic(err)
}
fmt.Printf("double(6) + 2 = %f\n", r) // will print : double(6) + 2 = 14.000000

"(1+2)3" 不报错

"(1+2)3" 输出结果3,感觉应该报错吧?
(1+2)*3,中间漏掉了符号。

0.7* 表达式无效

package main

import (
	"fmt"

	"github.com/dengsgo/math-engine/engine"
)

func main() {
	s := "0.7*"
	// call top level function
	r, err := engine.ParseAndExec(s)
	if err != nil {
		fmt.Println(err)
	}

	fmt.Println(r)
        // 0.7
}

类似 0.7- 、0.7+
这种表达式也是无效吧。

bug

计算这个会得到错误的结果:
(((3 / 3 - 3 - 3) / (3 * 3) / 3 / 3) - ((3 / 3) * (3 / 3) - ((3 * 3) * (3 * 3))) / ((3 / 3) * (3 / 3) - 3 * 3 / (3 / 3) * ((3 / 3) / 3 / 3 + 3 - 3 * (3 / 3))))

正确结果应该是:-1.8014398509481984e+17
math-engine结果: 7.272877265274083e+16

bug: "2_5*2" 结果是50

输入有异常符号

Tok:  strings.ReplaceAll(p.Source[start:p.offset], "_", ""),

代码直接替换了 "_",应该报错,或者返回0

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.