|
Boost Matheval
Evaluate mathematical expressions using Boost.Spirit
|
Boost Matheval is a libary built on top of Boost.Spirit, Boost.Fusion, and Boost.Phoenix to parse and evaluate mathematical expressions.
The interface consists of the class matheval::Parser and the convenience function matheval::parse function which both skip all whitespace in the input sequence, i.e. x+y is equivalent to x +\ty\n. The required type for the symbol table is std::map<std::string, double>.
If you want to parse a user provided or otherwise non-constant expression, you probably want to use the convenience function
If, however, you can reuse the expression and only want to evaluate for different values in the symbol table, you should use the class interface, because there you only pay the cost of parsing when actually calling matheval::Parser::parse.
Because the templates of Boost.Spirit take quite some time to instantiate the implementation is hidden behind an opaque pointer, so that you only have to compile all these templates once.
Commonly known arithmetic operations are supported:
x + yx - yx*yx/yx%y (fmod for floating point types)x**yMost functions of the standard math header <cmath> are supported. On top of that, Boost Matheval defines the mathematical sign function sgn.
absacosacosh (X3 only)asinasinh (X3 only)atanatanh (X3 only)cbrt (X3 only)ceilcoscoshdegerf (X3 only)erfc (X3 only)expexp2 (X3 only)floorisinfisnanloglog2 (X3 only)log10radround (X3 only)sgnsinsinhsqrttantanhtgamma (X3 only)Binary functions are rather uncommon in mathematics. Nevertheless there exist some:
atan2max (X3 only)min (X3 only)powCurrently only very few constants are defined.
eepsilonphipiVariables are composed of alphanumerical characters (a-z, A-Z, 0-9) and the underscore character _, but always start with a letter. In other words, variables cannot start with a digit or an underscore.
2.71828 (Euler's number) regardsless.