|
|||
Start page Features Build instructions Math parser interface Current version |
Example code
If you put all this together, you get the source code for a small application. The application defines a parser variables (" #include "muParser.h" // Function callback double MyFunction(double a_fVal) { return a_fVal*a_fVal; } // main program int main(int argc, char* argv[]) { using namespace mu; try { double fVal = 1; Parser p; p.DefineVar("a", &fVal); p.DefineFun("MyFunc", MyFunction); p.SetExpr("MyFunc(a)*pi+min(10,a)"); std::cout << p.Eval() << endl; } catch (Parser::exception_type &e) { std::cout << e.GetMsg() << endl; } return 0; } BenchmarksFinally, I'd like to give you some benchmarks. The benchmarking was done on an Intel Pentium P-4 with 2.6 GHz, with a version compiled by using MSVC++ 7.1 (Standard edition). The diagram shows number of evaluations per seconds vs. expression length. I compared both the static lib and the dll version with two other parsers that are freely available on the net, very fast and have a similar set of features. One of them is a commercial product.
A higher curve means better performance. Expressions were created randomly. They used only Release NotesRev 1.2: 14/04/2005First of all the interface has changed so this version is not backwards compatible. After receiving a couple of questions about it, this version features support for user defined binary operators. Consequently the built in operators can now be turned off, thus you can deactivate them and write complete customized parser subclasses that only contain the functionality you want. Other new feature is the introduction of callback functions taking string arguments, implicit generation of variables and the Assignement operator.
|