This C++ library offers a class which can be used to parse and evaluate a mathematical function from a string (which might be eg. requested from the user). The syntax of the function string is similar to mathematical expressions written in C/C++ (the exact syntax is specified in the documentation below). The function can then be evaluated with different values of variables.

For example, a function like "`sin(sqrt(x*x+y*y))`

" can be
parsed from a string (either `std::string`

or a C-style string)
and then evaluated with different values of `x`

and `y`

.
This library can be useful for evaluating user-inputted functions, or in
some cases interpreting mathematical expressions in a scripting language.

This library aims for maximum speed in both parsing and evaluation, while keeping maximum portability. The library should compile and work with any standard-conforming C++ compiler.

Different numerical types are supported: `double`

,
`float`

, `long double`

, `long int`

,
`std::complex`

(of types `double`

,
`float`

and `long double`

),
multiple-precision floating point numbers using the MPFR library, and
arbitrary precision integers using the GMP library. (Note that it's
not necessary for these two libraries to exist in the system in order
to use the Function Parser library with the other numerical types. Support
for these libraries is optionally compiled in using preprocessor settings.)

This Library is distributed under the Lesser General Public License (LGPL) version 3.

Download fparser4.5.1.zip v4.5.1 (released 11 Nov 2012)

(Older versions: v4.4.3, v4.3, v4.2, v4.1, v4.0.5, v3.3.2, v3.2.1, v3.1.5, v3.0.3, v2.84, v2.8, v2.71, v2.63, v2.51, v2.4, v2.3, v2.22)

Note that the library uses a few advanced (but still standard-conforming)
C++ techniques which might make it difficult if not impossible to compile it
with some old C++ compilers with poorer support for C++ features. The library
has been successfully tested with *gcc 4.3.x* and
*MS Visual C++ 2005*. Some very old compilers are known
to have problems compiling the library (such as *C++ Builder 6*
and older, and *gcc 2.x*.)

The basic library package above contains the bare minimum files intended for the usage of the library in C++ applications. If you want to simply use the library in your program, then download the package above.

The development version of the library is intended for those who want to modify and enhance the library. Besides the files contained in the basic package above, the development version contains the full optimizer sources, optimizer rule generation tools, an extensive automatic regression testbed, a Makefile and other tools.

Download the development package: fparser4.5.1_devel.tar.bz2

What's new in v4.5.1

- Reverted the automatic C++11 detection to a precompiler macro setting
(
`FP_SUPPORT_CPLUSPLUS11_MATH_FUNCS`

) because not all compilers yet fully support the C++11 math functions. - Fixed a potential duplicate symbol problem that happens with explicit template instantiations.

What's new in v4.5

- Removed support for the
`"eval()"`

function from the supported syntax. (This function was too dangerous, too difficult to maintain internally, not very useful, and more or less a gimmick in the first place.) - Removed several of the conditional compiling macro definitions, namely
`FP_SUPPORT_TR1_MATH`

,`FP_ENABLE_EVAL`

,`FP_EVAL_MAX_REC_LEVEL`

,`FP_NO_EVALUATION_CHECKS`

and`FP_EPSILON`

. - The epsilon value used in comparisons is now set with a member function of FunctionParser (which allows setting different values for different versions of the parser).
- The math functions previously turned on with
`FP_SUPPORT_TR1_MATH`

are now automatically used if`__cplusplus`

indicates that C++11 is in use. - Fixed some compilation problems with clang++.

You can also view the full version history.

- QCad: A GPL CAD software for various platforms.
- Fung-Calc: A GPL graphing calculator for both 2D and 3D graphs.
- Scribus - Open Source Desktop Publishing

Function Viewer: A small program I made to demonstrate the function parser.