soniah / evaler Goto Github PK
View Code? Open in Web Editor NEWImplements a simple floating point arithmetic expression evaluator in Go (golang).
License: BSD 3-Clause "New" or "Revised" License
Implements a simple floating point arithmetic expression evaluator in Go (golang).
License: BSD 3-Clause "New" or "Revised" License
.5 * 2 comes out as 10
fix is
var fp_rx = regexp.MustCompile(([0-9]*\.?[0-9]+)
)
I believe.
(and add a test like):
{".5 * 2", big.NewRat(1, 1), true}, // no leading zero
tried to submit, but I clearly dont know how to use github yet...so submitting as issue.
-s
BTW this was very simple to add to picol.go. Could use the module operator.
numbers that lead with '0' is radix 8 and '0x' is 16.
Unfortunately it gives an error if I try to pass a variable name which has a number in it;
For example, a map with
{"catX":"33"}
evaluates fine; but if I pass:
{"cat1":"33"}
it says that there is no such variable "cat", ignoring the number in the name
if there is no way to solve this, maybe indicate that in the "readme" file
for k := range symbolTable {
s += k
}
symbols_rx = regexp.MustCompile(fmt.Sprintf("(%s)", s))
func Tokenis (expr string) []string {
if symbols_rx != nil {
spaced = symbols_rx.ReplaceAllString(spaced, " ${1} ")//it doesn't work
}
}
The Eval function should also accept a hashmap of string -> float64 for passing variables and their values in. This should use a symboltable under the covers.
I will likely work on this feature.
It seems this lib is not goroutine-safe for there is a variable symbolTable in package.
This test case leads to a wrong result:
{"2*6**3+4**6", big.NewRat(4528, 1), true},
got 8624/1 expected 4528/1.
https://www.google.com/search?q=2*6^3%2B4^6
I think it's a problem in convert2postfix.
e.g.
sin(1) = 0.84
sin(0) = 0
...
ln(0) = 1
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.