SkillAgentSearch skills...

Exprtk

C++ Mathematical Expression Parsing And Evaluation Library https://www.partow.net/programming/exprtk/index.html

Install / Use

/learn @ArashPartow/Exprtk

README

C++ Mathematical Expression Toolkit Library Documentation

Section 00 - Introduction Section 01 - Capabilities Section 02 - Example Expressions Section 03 - Copyright Notice Section 04 - Downloads & Updates Section 05 - Installation Section 06 - Compilation Section 07 - Compiler Compatibility Section 08 - Built-In Operations & Functions Section 09 - Fundamental Types Section 10 - Components Section 11 - Compilation Options Section 12 - Expression Structures Section 13 - Variable, Vector & String Definition Section 14 - Vector Processing Section 15 - User Defined Functions Section 16 - Expression Dependents Section 17 - Hierarchies Of Symbol Tables Section 18 - Unknown Unknowns Section 19 - Enabling & Disabling Features Section 20 - Expression Return Values Section 21 - Compilation Errors Section 22 - Runtime Library Packages Section 23 - Helpers & Utils Section 24 - Runtime Checks Section 25 - Benchmarking Section 26 - Exprtk Notes Section 27 - Simple Exprtk Example Section 28 - Build Options Section 29 - Files Section 30 - Language Structure

[SECTION 00 - INTRODUCTION] The C++ Mathematical Expression Toolkit Library (ExprTk) is a simple to use, easy to integrate and extremely efficient run-time mathematical expression parsing and evaluation engine. The parsing engine supports numerous forms of functional and logic processing semantics and is easily extensible.


[SECTION 01 - CAPABILITIES]
The  ExprTk expression  evaluator supports  the following  fundamental
arithmetic operations, functions and processes:

 (00) Types:           Scalar, Vector, String

 (01) Basic operators: +, -, *, /, %, ^

 (02) Assignment:      :=, +=, -=, *=, /=, %=

 (03) Equalities &
      Inequalities:    =, ==, <>, !=, <, <=, >, >=

 (04) Logic operators: and, mand, mor, nand, nor, not, or, shl, shr,
                       xnor, xor, true, false

 (05) Functions:       abs, avg, ceil, clamp, equal, erf, erfc,  exp,
                       expm1, floor, frac,  log, log10, log1p,  log2,
                       logn, max,  min, mul,  ncdf,  not_equal, root,
                       round, roundn, sgn, sqrt, sum, swap, trunc

 (06) Trigonometry:    acos, acosh, asin, asinh, atan, atanh,  atan2,
                       cos,  cosh, cot,  csc, sec,  sin, sinc,  sinh,
                       tan, tanh, hypot, rad2deg, deg2grad,  deg2rad,
                       grad2deg

 (07) Control
      structures:      if-then-else, ternary conditional, switch-case,
                       return-statement

 (08) Loop statements: while, for, repeat-until, break, continue

 (09) String
      processing:      in, like, ilike, concatenation

 (10) Optimisations:   constant-folding, simple strength reduction and
                       dead code elimination

 (11) Runtime checks:  vector bounds, string bounds, loop iteration,
                       execution-time bounds and compilation process
                       checkpointing, assert statements

 (12) Calculus:        numerical integration and differentiation

[SECTION 02 - EXAMPLE EXPRESSIONS] The following is a short listing of infix format based mathematical expressions that can be parsed and evaluated using the ExprTk library.

(01) sqrt(1 - (3 / x^2)) (02) clamp(-1, sin(2 * pi * x) + cos(y / 2 * pi), +1) (03) sin(2.34e-3 * x) (04) if(((x[2] + 2) == 3) and ((y + 5) <= 9), 1 + w, 2 / z) (05) inrange(-2, m, +2) == if(({-2 <= m} and [m <= +2]), 1, 0) (06) ({1/1}[1/2]+(1/3)) - {1/4}^[1/5]+(1/6) - ({1/7}+[1/8](1/9)) (07) a * exp(2.2 / 3.3 * t) + c (08) z := x + sin(2.567 * pi / y) (09) u := 2.123 * {pi * z} / (w := x + cos(y / pi)) (10) 2x + 3y + 4z + 5w == 2 * x + 3 * y + 4 * z + 5 * w (11) 3(x + y) / 2.9 + 1.234e+12 == 3 * (x + y) / 2.9 + 1.234e+12 (12) (x + y)3.3 + 1 / 4.5 == [x + y] * 3.3 + 1 / 4.5 (13) (x + y[i])z + 1.1 / 2.7 == (x + y[i]) * z + 1.1 / 2.7 (14) (sin(x / pi) cos(2y) + 1) == (sin(x / pi) * cos(2 * y) + 1) (15) 75x^17 + 25.1x^5 - 35x^4 - 15.2x^3 + 40x^2 - 15.3x + 1 (16) (avg(x,y) <= x + y ? x - y : x * y) + 2.345 * pi / x (17) while (x <= 100) { x -= 1; } (18) x <= 'abc123' and (y in 'AString') or ('1x2y3z' != z) (19) ((x + 'abc') like '123') or ('a123b' ilike y) (20) sgn(+1.2^3.4z / -5.6y) <= {-7.8^9 / -10.11x }


[SECTION 03 - COPYRIGHT NOTICE]
Free  use  of  the  C++  Mathematical  Expression  Toolkit  Library is
permitted under the guidelines and in accordance with the most current
version of the MIT License.

   (1) https://www.opensource.org/licenses/MIT
   (2) SPDX-License-Identifier: MIT
   (3) SPDX-FileCopyrightText : Copyright (C) 1999-2025 Arash Partow

[SECTION 04 - DOWNLOADS & UPDATES] The most recent version of the C++ Mathematical Expression Toolkit Library including all updates and tests can be found at the following locations:

(1) Download: https://www.partow.net/programming/exprtk/index.html (2) Mirror Repository: https://github.com/ArashPartow/exprtk https://github.com/ArashPartow/exprtk-extras


[SECTION 05 - INSTALLATION]
The header  file exprtk.hpp  should be  placed in a project or  system
include path (e.g: /usr/include/).

[SECTION 06 - COMPILATION] The ExprTk package contains the ExprTk header, a set of simple examples and a benchmark and unit test suite. The following is a list of commands to build the various components:

(a) For a complete build: make clean all (b) For a PGO build: make clean pgo (c) To strip executables: make strip_bin (d) Execute valgrind check: make valgrind_check


[SECTION 07 - COMPILER COMPATIBILITY]
ExprTk has been built error and warning free using the following set
of C++ compilers:

  (*) GNU Compiler Collection (3.5+)
  (*) Clang/LLVM (1.1+)
  (*) Microsoft Visual Studio C++ Compiler (7.1+)
  (*) Intel C++ Compiler (8.x+)
  (*) AMD Optimizing C++ Compiler (1.2+)
  (*) Nvidia C++ Compiler (19.x+)
  (*) PGI C++ (10.x+)
  (*) Circle C++ (circa: b81c37d2bb227c)
  (*) IBM XL C/C++ (9.x+)
  (*) C++ Builder (XE4+)

[SECTION 08 - BUILT-IN OPERATIONS & FUNCTIONS]

(0) Arithmetic & Assignment Operators +----------+---------------------------------------------------------+ | OPERATOR | DEFINITION | +----------+---------------------------------------------------------+ | + | Addition between x and y. (eg: x + y) | +----------+---------------------------------------------------------+ | - | Subtraction between x and y. (eg: x - y) | +----------+---------------------------------------------------------+ | * | Multiplication between x and y. (eg: x * y) | +----------+---------------------------------------------------------+ | / | Division between x and y. (eg: x / y) | +----------+---------------------------------------------------------+ | % | Modulus of x with respect to y. (eg: x % y) | +----------+---------------------------------------------------------+ | ^ | x to the power of y. (eg: x ^ y) | +----------+---------------------------------------------------------+ | := | Assign the value of x to y. Where y is either a variable| | | or vector type. (eg: y := x) | +----------+---------------------------------------------------------+ | += | Increment x by the value of the expression on the right | | | hand side. Where x is either a variable or vector type. | | | (eg: x += abs(y - z)) | +----------+---------------------------------------------------------+ | -= | Decrement x by the value of the expression on the right | | | hand side. Where x is either a variable or vector type. | | | (eg: x[i] -= abs(y + z)) | +----------+---------------------------------------------------------+ | *= | Assign the multiplication of x by the value of the | | | expression on the righthand side to x. Where x is either| | | a variable or vector type. | | | (eg: x *= abs(y / z)) | +----------+---------------------------------------------------------+ | /= | Assign the division of x by the value of the expression | | | on the right-hand side to x. Where x is either a | | | variable or vector type. (eg: x[i + j] /= abs(y * z)) | +----------+---------------------------------------------------------+ | %= | Assign x modulo the value of the expression on the right| | | hand side to x. Where x is either a variable or vector | | | type. (eg: x[2] %= y ^ 2) | +----------+---------------------------------------------------------+

(1) Equalities & Inequalities +----------+---------------------------------------------------------+ | OPERATOR | DEFINITION | +----------+---------------------------------------------------------+ | == or = | True only if x is strictly equal to y. (eg: x == y) | +----------+---------------------------------------------------------+ | <> or != | True only if x does not equal y. (eg: x <> y or x != y) | +----------+---------------------------

Related Skills

View on GitHub
GitHub Stars947
CategoryDevelopment
Updated1d ago
Forks312

Languages

C++

Security Score

85/100

Audited on Mar 24, 2026

No findings