sandertv / go-formula Goto Github PK
View Code? Open in Web Editor NEWA go package for simple formula parsing and evaluation
License: MIT License
A go package for simple formula parsing and evaluation
License: MIT License
Can you please send me the traffic information for this package.
Insights -> Traffic -> Git clones and visitors.
case token.REM:
eval = func(vars vars) float64 {
return float64(int(x(vars)) % int(y(vars)))
}
}
I was wondering what the rationale was for casting to int as currently implemented. I'm assuming it's because % only supports int arguments.
Perhaps a better option is https://golang.org/pkg/math/#Mod or https://golang.org/pkg/math/#Remainder (not sure what the difference is)
What is your opinion on a version that operates only complex 128 instead of real?
It would be a performance benefit if constants can be loaded at the time of Formula
creation in New
function.
func New(formula string, variables ...Variable) (*Formula, error) {
...
}
Can I add more built-in functions.
I can do a PR with more functions from the math package
For V2 can we make this change?
package main
import (
"github.com/sandertv/go-formula/v2"
"log"
)
func main() {
f, err := formula.New("pi^e")
if err != nil {
log.Print(err)
return
}
x := formula.Var("x", 4.5)
z := formula.Var("z", 5)
log.Printf("Formula output: %v", f.Eval(x, z))
}
See: https://play.golang.org/p/-Kit-m2jbhK
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x4c84e1]
goroutine 1 [running]:
github.com/sandertv/go-formula/v2.(*Formula).Eval(0xc000096280, 0xc0000a0f48, 0x2, 0x2, 0x0)
/tmp/gopath030862853/pkg/mod/github.com/sandertv/go-formula/[email protected]/formula.go:64 +0x281
main.main()
/tmp/sandbox655706046/prog.go:16 +0x15e
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.