muParser - a fast math parser library
Version 2.1.0
My home
page
muParser
API-doc

### Introduction About the parser Release notes News Software using muParser Licence ### Features Features Overview Built in functions Built in binary operators Other operators ### Build instructions Building on Win32 Building on BSD/Linux Misc build instructions Including the files Compiler switches Where to ask for help ### Math parser interface Parser (de)initialization Evaluating an expression Single return value Multiple return values Bulk mode Setting the expression Defining identifier charsets Defining parser variables Explicit variable definition Implicit variable definition Defining constants Adding functionand operators Defining functions Defining operators Unary operators Binary operators Querying variables Querying constants Value recognition callbacks Removing variables/constants Localization Error handling Example code ### Current version Benchmarks | ## Features The following is a list of the features currently supported by the parser library. The primary objective is to keep it as extensible as possible whilst ensuring a maximum parsing speed. Extending the parser is mostly based on allowing a user to add custom callbacks which require only an absolute minimum of code. For instance you need exactly 2 lines of code to add a new function. But extending the parser may not be necessary at all since it comes with a powerful default implementation. Here is the (incomplete) list of features: ### Overview Easy to use You need only a few lines of code to evaluate en expression Optimized for speed High parsing performance if-then-else operator with lazy evaluation Compute multiple comma separated subexpressions in a single evaluation. (i.e. "sin(x), x+y, x*x") User-defined operators binary operators postfix operators infix operators User-defined functions with a fixed number of up to five arguments with variable number of arguments with a single string argument (for database queries) User-defined constants. numeric constants string constants User-defined variables. unlimited in number definable at parser runtime by the parser assigning variables in terms of other variables is possible Custom value recognition callbacks support for binary and hex values. can be used to implement database queries Default implementaion with many features 25 predefined functions. 14 predefined operators. Supports numerical differentiation with respect to a given variable. Assignement operator is supported Portability Project / makefiles for MSVC, mingw, autoconf, bcc ISO 14882 compliant code DLL version usable from every language able to use function exported in C-style Unit support Use postfix operators as unit multipliers `(3m -> 0.003)` Localization Argument separator, decimal separator, thousands separator can be adjusted to your locale ### The default implementation This section gives an overview on the default features supported by the parser. The default implementation is defined in the class `mu::Parser` located in the file muParser.cpp. The DLL-version uses this class internally. #### Built-in functions The following table gives an overview of the functions supported by the default implementation. It lists the function names, the number of arguments and a brief description.
Name | Argc. | Explanation
`sin` | 1 | sine function
`cos` | 1 | cosine function
`tan` | 1 | tangens function
`asin` | 1 | arcus sine function
`acos` | 1 | arcus cosine function
`atan` | 1 | arcus tangens function
`sinh` | 1 | hyperbolic sine function
`cosh` | 1 | hyperbolic cosine
`tanh` | 1 | hyperbolic tangens function
`asinh` | 1 | hyperbolic arcus sine function
`acosh` | 1 | hyperbolic arcus tangens function
`atanh` | 1 | hyperbolic arcur tangens function
`log2` | 1 | logarithm to the base 2
`log10` | 1 | logarithm to the base 10
`log` | 1 | logarithm to the base 10
`ln` | 1 | logarithm to base e (2.71828...)
`exp` | 1 | e raised to the power of x
`sqrt` | 1 | square root of a value
`sign` | 1 | sign function -1 if x<0; 1 if x>0
`rint` | 1 | round to nearest integer
`abs` | 1 | absolute value
`min` | var. | min of all arguments
`max` | var. | max of all arguments
`sum` | var. | sum of all arguments
`avg` | var. | mean value of all arguments
#### Built-in binary operators The following table lists the default binary operators supported by the parser.
Operator | Meaning | Priority
`=` | assignement | -1
`&&` | logical and | 1
`||` | logical or | 2
`<=` | less or equal | 4
`>=` | greater or equal | 4
`!=` | not equal | 4
`==` | equal | 4
`>` | greater than | 4
`<` | less than | 4
`+` | addition | 5
`-` | subtraction | 5
`*` | multiplication | 6
`/` | division | 6
`^` | raise x to the power of y | 7
*The assignment operator is special since it changes one of its arguments and can only by applied to variables. #### Other operators muParser has built in support for the if then else operator. It uses lazy evaluation in order to make sure only the necessary branch of the expression is evaluated.
Operator | Meaning | Remarks
`?:` | if then else operator | C++ style syntax
© 2005-2011 Ingo Berg | ^ TOP