muParser

muParser
muParser
Original author(s) Ingo Berg
Developer(s) Ingo Berg, Francesco Montorsi
Initial release 2005; 6 years ago (2005)
Stable release 1.34 / September 4, 2010; 13 months ago (2010-09-04)
Written in C++
Operating system Cross-platform
Platform 32-bit, 64-bit
Type Software library
License MIT License
Website muparser.sf.net

muParser is an extensible high-performance math expression parser library written in C++. It works by transforming a mathematical expression into bytecode and precalculating constant parts of the expression. It runs on both 32-bit and 64-bit architectures and has been tested using Visual C++ and GCC. The library is open source and distributed under the MIT License.[1]

Contents

Features

Here is a list of features currently supported by the parser library.[2]

Overview

  • Easy to use (only a few lines of code to evaluate an expression)
  • Extremely fast
  • User-defined operators (binary, postfix and infix)
  • User-defined functions
  • User-defined constants
  • User-defined variables
  • Custom value recognition callbacks
  • Default implementation
    • 26 predefined functions
    • 15 predefined operators
    • Supports numerical differentiation with respect to a given variable
    • Assignment 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 (postfix operators as unit multipliers)
  • Localization (of argument separator, decimal separator, thousands separator)

Built-in Functions

Name Argument Count 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
if 3 if ... then ... else ...
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 operators

Operator Meaning Priority
= assignment* -1
and logical and 1
or logical or 1
xor logical xor 1
<= less or equal 2
>= greater or equal 2
!= not equal 2
== equal 2
> greater than 2
< less than 2
+ addition 3
- subtraction 3
* multiplication 4
/ division 4
^ raise x to the power of y 5

*The assignment operator is special since it changes one of its arguments and can only be applied to variables.

Example Code

#include <iostream>
#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() << std::endl;
  }
  catch (Parser::exception_type &e)
  {
    std::cout << e.GetMsg() << std::endl;
  }
  return 0;
}

References


Wikimedia Foundation. 2010.

Игры ⚽ Поможем написать курсовую

Look at other dictionaries:

  • SciDAVis — 0.2.3 auf Fedora …   Deutsch Wikipedia

  • Vorest — Desarrollador Carlos Vilas Arias www.vorest.com …   Wikipedia Español

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”