MathEvaluator is quite a basic C++ library that evaluates infix math expressions. MathEvaluator has a focus on simplicity, simply one header file and implementation file that you include and compile into your project and only a few commands to get a working evalutation.
To compile ./test/test.cpp
you must compile ./include/evaluator.cpp
alongside it. This can be done with g++ ./test/test.cpp ./include/evaluator.cpp
.
You can compile the test cases with make cd build
make
.
Install emscripten and compile ./test/test.cpp
with em++ ./test/test.cpp ./include/evaluator.cpp
.
double result = evaluate("1+1"); // returns 2
MathEvaluator evalutor;
double result = evalutor.eval("1+1"); // returns 2
MathEvaluator evalutor;
double x = 20;
evalutor.appendVariable("x", x);
double result = evalutor.eval("1+x"); // returns 21
MathEvaluator evalutor;
double x = 20;
evalutor.appendVariable("x", x);
double result1 = evalutor.eval("1+x"); // returns 21
x = 10;
double result2 = evalutor.eval("1+x"); // returns 11
MathEvaluator evalutor;
double result = evalutor.eval("sin(1.5707963267948966)"); // returns 1