muparser - fast math parser library

About the the muparser library

Many applications require the parsing of mathematical expressions. The main objective muparser is to provide a fast, easy and secure 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. For best performance muparser allows parallelized evaluation of expressions with OpenMP. parallelized evaluation of expressions with OpenMP.

The library was designed with portability in mind and should compile on every standard compliant C++ compiler. The build system is based on CMake. The code runs on both 32 bit and 64 bit architechtures and has been tested using Visual Studio 2019, CLANG and GCC. Code samples are provided in order to help you understand its usage. The library is open source and distributed under the BSD - Clause 2 "Simplified" Licence . The source code archive of the last stable version is available for download here:

Download Latest muparser release

The muparser library is in "production" state. Code changes are kept to a minimum with little active development. The main focus is put on bug fixing and keeping the archive compatible with the current generation of C++ compilers.


This library is open source. Over the course of time many people have contributed in one way or another to the project. The complete list of contributors can be viewed at GitHub. Special thanks to Julien Schueller and Francis Giraldeau for setting up the CMake build system as well as Travis-CI and Appveyor integration. There would not be a CMake based build system without them.

Example code

Using muparser is pretty straightforward. The following example defines a parser variable named "a" and adds a user defined functions named "MyFunc". When using the parser, make sure that you don't forget to catch possible of type Parser::exception_type.

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

double MySqr(double a_fVal) {  return a_fVal*a_fVal; }

int main(int argc, char *argv[])
		double var_a = 1;
		mu::Parser p;
		p.DefineVar("a", &var_a); 
		p.DefineFun("MySqr", MySqr); 

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

Release Notes for Version 2.3.2

Changes to 2.3.0 and 2.3.1

Those releases were shortlived and replaced within days due to several issues. Version 2.3.2 is the successor to version 2.2.6.

Changes to 2.2.6:

  • using OpenMP is now the default settings for cmake based builds
  • added optimization for trivial expressions. (Expressions whose RPN only has a single entry)
  • introduced a maximum length for expressions (5000 Character)
  • introduced a maximum length for identifiers (100 Characters)
  • removed the MUP_MATH_EXCEPTION macro and related functionality. (C++ exceptions for divide by zero or sqrt of a negative number are no longer supported)
  • removed ParserStack.h (replaced with std::stack)
  • removed macros for defining E and PI (replaced with a static constants)
  • the MUP_ASSERT macro is no longer removed in release builds for better protection against segmentation faults

Security Fixes:

The issues following issues were fixed. They are present in previous stable releases.


  • Fixed an issue where the bulk mode could hang on GCC/CLANG builds due to OpenMP chunksize dropping below 1.

API and ABI compliance check with version 2.2.6

Version 2.3 extends existing enumerators. New Error codes have been added. In the muparser base class protected functions for implementing basic mathematical operations such as sin,cos, sqrt, tan,... have been removed.

The binary interface should be compatible with versions 2.2.6 unless the parser is used in ways that i did not forsee. I checked the compliance against the sample application compiled for 2.2.6 by exchanging the library with the new version 2.3.2. I did not see any problems. You can find a complete ABI compliance report here. I recommend replacing existing versions of 2.2.6 with version 2.3.2. Please report all incompatibilities that you find (API and ABI).