muparser - Fast Math Parser Library
Version 2.2.5

About the the muparser library

Many applications require the parsing of mathematical expressions. The main objective of this library is to provide a fast and easy way of doing this. 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.

The library was designed with portability in mind and should compile on every standard compliant C++ compiler. Wrapper for C and C# exist. The parser archive contains a ready to use project and makefiles files for a variety of platforms. The code runs on both 32 bit and 64 bit architechtures and has been tested using Visual Studio 2013 and GCC V4.8.1. Code samples are provided in order to help you understand its usage. The library is open source and distributed under the MIT license. The source code archive of the last stable version is available for download here:

muParser download

The muparser project is in "production" state. This means that code changes are kept to a minimum with little active development. The main focus is currently put on bug fixing and keeping the archive compatible with the current generation of C++ compilers. You can obtain the latest version via the Github Project Page.

Example code

Using muparser is pretty straightforward as you can see in the following example. The sample defines a parser variables ("a") and adds a user defined functions named "MyFunc". When using the parser make sure that you don't forget to catch possible exceptions of type Parser::exception_type.

#include <iostream>
#include "muParser.h"

// Function callback
double MySqr(double a_fVal) 
  return a_fVal*a_fVal; 

// main program
int main(int argc, char* argv[])
  using namespace mu;

    double fVal = 1;
    Parser p;
    p.DefineVar("a", &fVal); 
    p.DefineFun("MySqr", MySqr); 

    for (std::size_t a=0; a<100; ++a)
      fVal = a;  // Change value of variable a
      std::cout << p.Eval() << std::endl;
  catch (Parser::exception_type &e)
    std::cout << e.GetMsg() << std::endl;
  return 0;

You might also like: