C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html

This commit is contained in:
Arash Partow 2013-07-09 08:32:08 +10:00
parent b112725a97
commit 2a9a16fd66
3 changed files with 1133 additions and 601 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1409,6 +1409,152 @@ inline bool run_test02()
test_ab<T>("inrange(a,b,'ccc')" ,"aaa","bbb",T(1.0)), test_ab<T>("inrange(a,b,'ccc')" ,"aaa","bbb",T(1.0)),
test_ab<T>("inrange('aaa',b,c)" ,"aaa","bbb",T(1.0)), test_ab<T>("inrange('aaa',b,c)" ,"aaa","bbb",T(1.0)),
test_ab<T>("inrange('aaa',b,c)" ,"aaa","bbb",T(1.0)), test_ab<T>("inrange('aaa',b,c)" ,"aaa","bbb",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == '0123456789' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == '0123456789'[:] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == '0123456789'[0:]","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == '0123456789'[:9]","","",T(1.0)),
test_ab<T>("'01234567890123456789'[:9] == '0123456789'[:9]","","",T(1.0)),
test_ab<T>("'01234567890123456789'[10:] == '0123456789'[:] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != '123456789' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != '123456789'[:] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != '123456789'[0:] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != '123456789'[:8] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[:9] != '123456789'[:8] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[10:] != '123456789'[:] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[2*6:10+6] == '23456' ","","",T(1.0)),
test_ab<T>("'0123456789' == '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'0123456789'[:] == '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'0123456789'[0:] == '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'0123456789'[:9] == '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'0123456789'[:9] == '01234567890123456789'[:9] ","","",T(1.0)),
test_ab<T>("'0123456789'[:] == '01234567890123456789'[10:]","","",T(1.0)),
test_ab<T>("'123456789' != '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'123456789'[:] != '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'123456789'[0:] != '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'123456789'[:8] != '01234567890123456789'[0:9]","","",T(1.0)),
test_ab<T>("'123456789'[:8] != '01234567890123456789'[:9] ","","",T(1.0)),
test_ab<T>("'123456789'[:] != '01234567890123456789'[10:]","","",T(1.0)),
test_ab<T>("'23456' == '01234567890123456789'[2*6:10+6] ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r0: 6] == '23456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[2: r1] == '23456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r0:3*2] == '23456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[1+1:r1] == '23456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r0: ] == '234567890123456789' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[: r1] == '0123456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r0:r1] == '23456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r0:r1+2] == '2345678' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r0+2:r1] == '456' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[r1-r0:] == '4567890123456789' ","","",T(1.0)),
test_ab<T>("'01234567890123456789'[:r1-r0] == '01234' ","","",T(1.0)),
test_ab<T>("'23456' == '01234567890123456789'[r0: 6] ","","",T(1.0)),
test_ab<T>("'23456' == '01234567890123456789'[2: r1] ","","",T(1.0)),
test_ab<T>("'23456' == '01234567890123456789'[r0:3*2] ","","",T(1.0)),
test_ab<T>("'23456' == '01234567890123456789'[1+1:r1] ","","",T(1.0)),
test_ab<T>("'234567890123456789' == '01234567890123456789'[r0: ] ","","",T(1.0)),
test_ab<T>("'0123456' == '01234567890123456789'[: r1] ","","",T(1.0)),
test_ab<T>("'23456' == '01234567890123456789'[r0:r1] ","","",T(1.0)),
test_ab<T>("'2345678' == '01234567890123456789'[r0:r1+2] ","","",T(1.0)),
test_ab<T>("'456' == '01234567890123456789'[r0+2:r1] ","","",T(1.0)),
test_ab<T>("'4567890123456789' == '01234567890123456789'[r1-r0:] ","","",T(1.0)),
test_ab<T>("'01234' == '01234567890123456789'[:r1-r0] ","","",T(1.0)),
test_ab<T>("a[r0: 6] == '23456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[2: r1] == '23456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r0:3*2] == '23456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[1+1:r1] == '23456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r0: ] == '234567890123456789' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[: r1] == '0123456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r0:r1] == '23456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r0:r1+2] == '2345678' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r0+2:r1] == '456' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r1-r0:] == '4567890123456789' ","01234567890123456789","",T(1.0)),
test_ab<T>("a[:r1-r0] == '01234' ","01234567890123456789","",T(1.0)),
test_ab<T>("'23456' == a[r0: 6] ","01234567890123456789","",T(1.0)),
test_ab<T>("'23456' == a[2: r1] ","01234567890123456789","",T(1.0)),
test_ab<T>("'23456' == a[r0:3*2] ","01234567890123456789","",T(1.0)),
test_ab<T>("'23456' == a[1+1:r1] ","01234567890123456789","",T(1.0)),
test_ab<T>("'234567890123456789' == a[r0: ] ","01234567890123456789","",T(1.0)),
test_ab<T>("'0123456' == a[: r1] ","01234567890123456789","",T(1.0)),
test_ab<T>("'23456' == a[r0:r1] ","01234567890123456789","",T(1.0)),
test_ab<T>("'2345678' == a[r0:r1+2] ","01234567890123456789","",T(1.0)),
test_ab<T>("'456' == a[r0+2:r1] ","01234567890123456789","",T(1.0)),
test_ab<T>("'4567890123456789' == a[r1-r0:] ","01234567890123456789","",T(1.0)),
test_ab<T>("'01234' == a[:r1-r0] ","01234567890123456789","",T(1.0)),
test_ab<T>("a[r0: 6] == b " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("a[2: r1] == b " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("a[r0:3*2] == b " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("a[1+1:r1] == b " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("a[r0: ] == b " ,"01234567890123456789","234567890123456789",T(1.0)),
test_ab<T>("a[: r1] == b " ,"01234567890123456789","0123456",T(1.0)),
test_ab<T>("a[r0:r1] == b " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("a[r0:r1+2] == b " ,"01234567890123456789","2345678",T(1.0)),
test_ab<T>("a[r0+2:r1] == b " ,"01234567890123456789","456",T(1.0)),
test_ab<T>("a[r1-r0:] == b " ,"01234567890123456789","4567890123456789",T(1.0)),
test_ab<T>("a[:r1-r0] == b " ,"01234567890123456789","01234",T(1.0)),
test_ab<T>("b == a[r0: 6] " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("b == a[2: r1] " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("b == a[r0:3*2] " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("b == a[1+1:r1] " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("b == a[r0: ] " ,"01234567890123456789","234567890123456789",T(1.0)),
test_ab<T>("b == a[: r1] " ,"01234567890123456789","0123456",T(1.0)),
test_ab<T>("b == a[r0:r1] " ,"01234567890123456789","23456",T(1.0)),
test_ab<T>("b == a[r0:r1+2] " ,"01234567890123456789","2345678",T(1.0)),
test_ab<T>("b == a[r0+2:r1] " ,"01234567890123456789","456",T(1.0)),
test_ab<T>("b == a[r1-r0:] " ,"01234567890123456789","4567890123456789",T(1.0)),
test_ab<T>("b == a[:r1-r0] " ,"01234567890123456789","01234",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == a ","0123456789","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == a[:] ","0123456789","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == a[0:] ","0123456789","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] == a[:9] ","0123456789","",T(1.0)),
test_ab<T>("'01234567890123456789'[:9] == a[:9] ","0123456789","",T(1.0)),
test_ab<T>("'01234567890123456789'[10:] == a[:] ","0123456789","",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != a ","123456789" ,"",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != a[:] ","123456789" ,"",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != a[0:] ","123456789" ,"",T(1.0)),
test_ab<T>("'01234567890123456789'[0:9] != a[:8] ","123456789" ,"",T(1.0)),
test_ab<T>("'01234567890123456789'[:9] != a[:8] ","123456789" ,"",T(1.0)),
test_ab<T>("'01234567890123456789'[10:] != a[:] ","123456789" ,"",T(1.0)),
test_ab<T>("'01234567890123456789'[2*6:10+6] == a","23456" ,"",T(1.0)),
test_ab<T>("'23456' == a[:] ","23456" ,"",T(1.0)),
test_ab<T>("a == '01234567890123456789'[0:9] ","0123456789","",T(1.0)),
test_ab<T>("a[:] == '01234567890123456789'[0:9] ","0123456789","",T(1.0)),
test_ab<T>("a[0:] == '01234567890123456789'[0:9] ","0123456789","",T(1.0)),
test_ab<T>("a[:9] == '01234567890123456789'[0:9] ","0123456789","",T(1.0)),
test_ab<T>("a[:9] == '01234567890123456789'[:9] ","0123456789","",T(1.0)),
test_ab<T>("a[:] == '01234567890123456789'[10:] ","0123456789","",T(1.0)),
test_ab<T>("a != '01234567890123456789'[0:9] ","123456789" ,"",T(1.0)),
test_ab<T>("a[:] != '01234567890123456789'[0:9] ","123456789" ,"",T(1.0)),
test_ab<T>("a[0:] != '01234567890123456789'[0:9] ","123456789" ,"",T(1.0)),
test_ab<T>("a[:8] != '01234567890123456789'[0:9] ","123456789" ,"",T(1.0)),
test_ab<T>("a[:8] != '01234567890123456789'[:9] ","123456789" ,"",T(1.0)),
test_ab<T>("a[:] != '01234567890123456789'[10:] ","123456789" ,"",T(1.0)),
test_ab<T>("a == '01234567890123456789'[2*6:10+6]","23456" ,"",T(1.0)),
test_ab<T>("a[:] == '23456' ","23456" ,"",T(1.0)),
test_ab<T>("a[0:9] == b ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("a[0:9] == b[:] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("a[0:9] == b[0:] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("a[0:9] == b[:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("a[:9] == b[:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("a[10:] == b[:] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("a[0:9] != b ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("a[0:9] != b[:] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("a[0:9] != b[0:] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("a[0:9] != b[:8] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("a[:9] != b[:8] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("a[10:] != b[:] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("a[2*6:10+6] == b ","01234567890123456789","23456" ,T(1.0)),
test_ab<T>("b == a[0:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("b[:] == a[0:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("b[0:] == a[0:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("b[:9] == a[0:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("b[:9] == a[:9] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("b[:] == a[10:] ","01234567890123456789","0123456789",T(1.0)),
test_ab<T>("b != a[0:9] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("b[:] != a[0:9] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("b[0:] != a[0:9] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("b[:8] != a[0:9] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("b[:8] != a[:9] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("b[:] != a[10:] ","01234567890123456789","123456789" ,T(1.0)),
test_ab<T>("b == a[2*6:10+6] ","01234567890123456789","23456" ,T(1.0)),
test_ab<T>("a[2:6] == b" ,"0123456789","23456" ,T(1.0)), test_ab<T>("a[2:6] == b" ,"0123456789","23456" ,T(1.0)),
test_ab<T>("a == b[2:6]" ,"23456","0123456789" ,T(1.0)), test_ab<T>("a == b[2:6]" ,"23456","0123456789" ,T(1.0)),
test_ab<T>("a[1+1:2*3] == b" ,"0123456789","23456" ,T(1.0)), test_ab<T>("a[1+1:2*3] == b" ,"0123456789","23456" ,T(1.0)),
@ -1452,10 +1598,15 @@ inline bool run_test02()
std::string str_b; std::string str_b;
std::string str_c; std::string str_c;
T r0 = T(2);
T r1 = T(6);
exprtk::symbol_table<T> symbol_table; exprtk::symbol_table<T> symbol_table;
symbol_table.add_stringvar("a" ,str_a); symbol_table.add_stringvar("a" ,str_a);
symbol_table.add_stringvar("b" ,str_b); symbol_table.add_stringvar("b" ,str_b);
symbol_table.add_stringvar("c" ,str_c); symbol_table.add_stringvar("c" ,str_c);
symbol_table.add_variable ("r0", r0);
symbol_table.add_variable ("r1", r1);
exprtk::expression<T> expression; exprtk::expression<T> expression;
expression.register_symbol_table(symbol_table); expression.register_symbol_table(symbol_table);
@ -2976,11 +3127,11 @@ inline bool run_test15()
"/* Comment 11*/2 - (x + y) / z/* Comment 12*/", "/* Comment 11*/2 - (x + y) / z/* Comment 12*/",
"/* Comment 13*/2 - (x + y) / z/* Comment 14*/\n", "/* Comment 13*/2 - (x + y) / z/* Comment 14*/\n",
"2 - /* Comment 15 */(x + y) / z", "2 - /* Comment 15 */(x + y) / z",
"2 - /* Comment 15 */(x + y) /* Comment 16 *// z \n", "2 - /* Comment 16 */(x + y) /* Comment 17 *// z \n",
"2 - /* Comment 17 */(x + y) /* Comment 18 */ / z //Comment 19\n", "2 - /* Comment 18 */(x + y) /* Comment 19 */ / z //Comment 20\n",
"2 - /* Comment 20 */(x + y) /* Comment 21 */ / z #Comment 22\n", "2 - /* Comment 21 */(x + y) /* Comment 22 */ / z #Comment 23\n",
"2 - /* Comment 23 */(x + y) /* Comment 24 */ / z //Comment 25", "2 - /* Comment 24 */(x + y) /* Comment 25 */ / z //Comment 26",
"2 - /* Comment 26 */(x + y) /* Comment 27 */ / z #Comment 28" "2 - /* Comment 27 */(x + y) /* Comment 28 */ / z #Comment 29"
}; };
static const std::size_t expr_str_list_size = sizeof(expr_str_list) / sizeof(std::string); static const std::size_t expr_str_list_size = sizeof(expr_str_list) / sizeof(std::string);

View File

@ -31,7 +31,7 @@ operations, functions and processes:
(5) Conditional, (5) Conditional,
Switch & Switch &
Loop statements: if-then-else, switch-case, while Loop statements: if-then-else, switch-case, while, repeat-until
(6) Assignment: := (6) Assignment: :=
@ -43,7 +43,7 @@ operations, functions and processes:
[02 - EXAMPLE EXPRESSIONS] [02 - EXAMPLE EXPRESSIONS]
The following is a short sample of the types of mathematical The following is a short listing of the types of mathematical
expressions that can be parsed and evaluated using the ExprTk library. expressions that can be parsed and evaluated using the ExprTk library.
(01) sqrt(1 - (x^2)) (01) sqrt(1 - (x^2))
@ -102,7 +102,7 @@ include path (e.g: /usr/include/).
[07 - COMPILER COMPATIBILITY] [07 - COMPILER COMPATIBILITY]
(*) GNU Compiler Collection (4.3+) (*) GNU Compiler Collection (4.1+)
(*) Intel® C++ Compiler (9.x+) (*) Intel® C++ Compiler (9.x+)
(*) Clang/LLVM (1.1+) (*) Clang/LLVM (1.1+)
(*) PGI C++ (10.x+) (*) PGI C++ (10.x+)
@ -115,209 +115,214 @@ include path (e.g: /usr/include/).
[08 - BUILT-IN OPERATIONS & FUNCTIONS] [08 - BUILT-IN OPERATIONS & FUNCTIONS]
(0) Arithmetic Operators (0) Arithmetic Operators
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| OPERATOR | DEFINITION | | OPERATOR | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| + | Addition between x and y. (eg: x + y) | | + | Addition between x and y. (eg: x + y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| - | Subtraction between x and y. (eg: x - y) | | - | Subtraction between x and y. (eg: x - y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| * | Multiplication between x and y. (eg: x * y) | | * | Multiplication between x and y. (eg: x * y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| / | Division 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) | | % | Modulus of x with respect to y. (eg: x % y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| ^ | x to the power of y. (eg: x ^ y) | | ^ | x to the power of y. (eg: x ^ y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| := | Assign the value of x to y. (eg: y := x) | | := | Assign the value of x to y. (eg: y := x) |
| | where y is a variable type. | | | Where y is a variable type. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| <=> | Swap the values of x and y. (eg: x <=> y) |
| | Where both x and y are variables. |
+----------+---------------------------------------------------------+
(1) Equalities & Inequalities (1) Equalities & Inequalities
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| OPERATOR | DEFINITION | | OPERATOR | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| == or = | True only if x is strictly equal to y. (eg: x == y) | | == 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) | | <> or != | True only if x does not equal y (eg: x <> y or x != y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| < | True only if x is less than y. (eg: x < y) | | < | True only if x is less than y. (eg: x < y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| <= | True only if x is less than or equal to y. (eg: x <= y) | | <= | True only if x is less than or equal to y. (eg: x <= y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| > | True only if x is greater than y. (eg: x > y) | | > | True only if x is greater than y. (eg: x > y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| >= | True only if x greater than or equal to y (eg: x >= y) | | >= | True only if x greater than or equal to y (eg: x >= y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
(2) Boolean Operations (2) Boolean Operations
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| OPERATOR | DEFINITION | | OPERATOR | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| true | True state or any value other than zero (typically 1). | | true | True state or any value other than zero (typically 1). |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| false | False state, value of zero. | | false | False state, value of zero. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| and | Logical AND, True only if x and y are both true. | | and | Logical AND, True only if x and y are both true. |
| | (eg: x and y) | | | (eg: x and y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| mand | Multi-input logical AND, True only if all inputs are | | mand | Multi-input logical AND, True only if all inputs are |
| | true. Left to right short-circuiting of expressions. | | | true. Left to right short-circuiting of expressions. |
| | (eg: mand(x > y,z < w,u or v,w and x)) | | | (eg: mand(x > y,z < w,u or v,w and x)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| mor | Multi-input logical OR, True if at least one of the | | mor | Multi-input logical OR, True if at least one of the |
| | inputs are true. Left to right short-circuiting of | | | inputs are true. Left to right short-circuiting of |
| | expressions. (eg: mand(x > y,z < w,u or v,w and x)) | | | expressions. (eg: mand(x > y,z < w,u or v,w and x)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| nand | Logical NAND, True only if either x or y is false. | | nand | Logical NAND, True only if either x or y is false. |
| | (eg: x nand y) | | | (eg: x nand y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| nor | Logical NOR, True only if the result of x or y is false | | nor | Logical NOR, True only if the result of x or y is false |
| | (eg: x nor y) | | | (eg: x nor y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| not | Logical NOT, Negate the logical sense of the input. | | not | Logical NOT, Negate the logical sense of the input. |
| | (eg: not(x and y) == x nand y) | | | (eg: not(x and y) == x nand y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| or | Logical OR, True if either x or y is true. (eg: x or y) | | or | Logical OR, True if either x or y is true. (eg: x or y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| xor | Logical XOR, True only if the logical states of x and y | | xor | Logical XOR, True only if the logical states of x and y |
| | differ. (eg: x xor y) | | | differ. (eg: x xor y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| xnor | Logical XNOR, True iff the biconditional of x and y is | | xnor | Logical XNOR, True iff the biconditional of x and y is |
| | satisfied. (eg: x xnor y) | | | satisfied. (eg: x xnor y) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| & | Similar to AND but with left to right expression short | | & | Similar to AND but with left to right expression short |
| | circuiting optimisation. (eg: (x & y) == (y and x)) | | | circuiting optimisation. (eg: (x & y) == (y and x)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| | | Similar to OR but with left to right expression short | | | | Similar to OR but with left to right expression short |
| | circuiting optimisation. (eg: (x | y) == (y or x)) | | | circuiting optimisation. (eg: (x | y) == (y or x)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
(3) General Purpose Functions (3) General Purpose Functions
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| FUNCTION | DEFINITION | | FUNCTION | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| abs | Absolute value of x. | | abs | Absolute value of x. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| avg | Average of all the inputs. | | avg | Average of all the inputs. |
| | (eg: avg(x,y,z,w,u,v) == (x + y + z + w + u + v) / 6) | | | (eg: avg(x,y,z,w,u,v) == (x + y + z + w + u + v) / 6) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| ceil | Smallest integer that is greater than or equal to x. | | ceil | Smallest integer that is greater than or equal to x. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| clamp | Clamp x in range between r0 and r1, where r0 < r1. | | clamp | Clamp x in range between r0 and r1, where r0 < r1. |
| | (eg: clamp(r0,x,r1) | | | (eg: clamp(r0,x,r1) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| equal | Equality test between x and y using normalized epsilon | | equal | Equality test between x and y using normalized epsilon |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| erf | Error function of x | | erf | Error function of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| erfc | Complimentary error function of x | | erfc | Complimentary error function of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| exp | e to the power of x | | exp | e to the power of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| floor | Largest integer that is less than or equal to x. | | floor | Largest integer that is less than or equal to x. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| frac | Fractional portion of x | | frac | Fractional portion of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| hypot | Hypotenuse of x and y (eg: hypot(x,y) = sqrt(x*x + y*y))| | hypot | Hypotenuse of x and y (eg: hypot(x,y) = sqrt(x*x + y*y))|
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| log | Natural logarithm of x | | log | Natural logarithm of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| log10 | Base 10 logarithm of x | | log10 | Base 10 logarithm of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| log1p | Natural logarithm of 1 + x, where x is very small. | | log1p | Natural logarithm of 1 + x, where x is very small. |
| | (eg: log1p(x)) | | | (eg: log1p(x)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| log2 | Base 2 logarithm of x | | log2 | Base 2 logarithm of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| logn | Base N logarithm of x (eg: logn(1235,8)) | | logn | Base N logarithm of x (eg: logn(1235,8)) |
| | where n > 0 and is an integer. | | | where n > 0 and is an integer. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| max | Largest value of all the inputs. (eg: max(x,y,z,w,u,v)) | | max | Largest value of all the inputs. (eg: max(x,y,z,w,u,v)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| min | Smallest value of all the inputs. (eg: min(x,y,z,w,u)) | | min | Smallest value of all the inputs. (eg: min(x,y,z,w,u)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| mul | Product of all the inputs. | | mul | Product of all the inputs. |
| | (eg: mul(x,y,z,w,u,v,t) == (x * y * z * w * u * v * t)) | | | (eg: mul(x,y,z,w,u,v,t) == (x * y * z * w * u * v * t)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| nequal | Not-equal test between x and y using normalized epsilon | | nequal | Not-equal test between x and y using normalized epsilon |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| root | Nth-Root of x (eg: root(x,3)) | | root | Nth-Root of x (eg: root(x,3)) |
| | where n > 0 and is an integer. | | | where n > 0 and is an integer. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| round | Round x to the nearest integer. | | round | Round x to the nearest integer. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| roundn | Round x to the n decimal places (eg: roundn(x,4)) | | roundn | Round x to n decimal places (eg: roundn(x,3)) |
| | where n > 0 and is an integer. | | | where n > 0 and is an integer. |
+-----------+--------------------------------------------------------+ | | (eg: roundn(1.2345678,4) == 1.2346) |
+----------+---------------------------------------------------------+
| sgn | Sign of x, -1 where x < 0, +1 where x > 0, else zero. | | sgn | Sign of x, -1 where x < 0, +1 where x > 0, else zero. |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| sqrt | Square root of x, where x > 0 | | sqrt | Square root of x, where x > 0 |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| sum | Sum of all the inputs. | | sum | Sum of all the inputs. |
| | (eg: sum(x,y,z,w,u,v,t) == (x + y + z + w + u + v + t)) | | | (eg: sum(x,y,z,w,u,v,t) == (x + y + z + w + u + v + t)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| trunc | Integer portion of x | | trunc | Integer portion of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
(4) Trigonometry Functions (4) Trigonometry Functions
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| FUNCTION | DEFINITION | | FUNCTION | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| acos | Arc cosine of x expressed in radians. Interval [-1,+1] | | acos | Arc cosine of x expressed in radians. Interval [-1,+1] |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| asin | Arc sine of x expressed in radians. Interval [-1,+1] | | asin | Arc sine of x expressed in radians. Interval [-1,+1] |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| atan | Arc tangent of x expressed in radians. Interval [-1,+1] | | atan | Arc tangent of x expressed in radians. Interval [-1,+1] |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| atan2 | Arc tangent of x expressed in radians. Interval [-1,+1]| | atan2 | Arc tangent of (x/y) expressed in radians. [-pi,+pi] |
+-----------+--------------------------------------------------------+ | | eg: atan2(x,y) |
+----------+---------------------------------------------------------+
| cos | Cosine of x | | cos | Cosine of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| cosh | Hyperbolic cosine of x | | cosh | Hyperbolic cosine of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| cot | Cotangent of x | | cot | Cotangent of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| csc | Cosecant of x | | csc | Cosecant of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| sec | Secant of x | | sec | Secant of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| sin | Sine of x | | sin | Sine of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| sinh | Hyperbolic sine of x | | sinh | Hyperbolic sine of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| tan | Tangent of x | | tan | Tangent of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| tanh | Hyperbolic tangent of x | | tanh | Hyperbolic tangent of x |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| deg2rad | Convert x from degrees to radians | | deg2rad | Convert x from degrees to radians |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| deg2grad | Convert x from degrees to gradians | | deg2grad | Convert x from degrees to gradians |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| rad2deg | Convert x from radians to degrees | | rad2deg | Convert x from radians to degrees |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| grad2deg | Convert x from gradians to degrees | | grad2deg | Convert x from gradians to degrees |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
(5) String Processing (5) String Processing
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| FUNCTION | DEFINITION | | FUNCTION | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| in | True only if x is a substring of y | | in | True only if x is a substring of y |
| | (eg: x in y or 'abc' in 'abcdefgh') | | | (eg: x in y or 'abc' in 'abcdefgh') |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| like | True only if the string x matches the pattern y. | | like | True only if the string x matches the pattern y. |
| | Available wildcard characters are '*' and '?' denoting | | | Available wildcard characters are '*' and '?' denoting |
| | zero or more and zero or one matches respectively. | | | zero or more and zero or one matches respectively. |
| | (eg: x like y or 'abcdefgh' like 'a?d*h') | | | (eg: x like y or 'abcdefgh' like 'a?d*h') |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| like | True only if the string x matches the pattern y in a | | ilike | True only if the string x matches the pattern y in a |
| | case insensitive manner. Available wildcard characters | | | case insensitive manner. Available wildcard characters |
| | are '*' and '?' denoting zero or more and zero or one | | | are '*' and '?' denoting zero or more and zero or one |
| | matches respectively. | | | matches respectively. |
| | (eg: x ilike y or 'a1B2c3D4e5F6g7H' like 'a?d*h') | | | (eg: x ilike y or 'a1B2c3D4e5F6g7H' ilike 'a?d*h') |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| [r0:r1] | The closed interval [r0,r1] of the specified string. | | [r0:r1] | The closed interval [r0,r1] of the specified string. |
| | eg: Given a string x with a value of 'abcdefgh' then: | | | eg: Given a string x with a value of 'abcdefgh' then: |
| | 0. x[1:4] == 'bcde' | | | 0. x[1:4] == 'bcde' |
@ -325,15 +330,20 @@ include path (e.g: /usr/include/).
| | 2. x[3: ] == 'cdefgh' | | | 2. x[3: ] == 'cdefgh' |
| | 3. x[ : ] == 'abcdefgh' | | | 3. x[ : ] == 'abcdefgh' |
| | 4. x[4/2:3+2] == x[2:5] == 'cdef' | | | 4. x[4/2:3+2] == x[2:5] == 'cdef' |
+-----------+--------------------------------------------------------+ | | |
| | Note: Both r0 and r1 are assumed to be integers. They |
| | may also be the result of an expression, in the event |
| | they have fractional components truncation will be |
| | performed. (eg: 1.67 -> 1) |
+----------+---------------------------------------------------------+
(6) Control Structures (6) Control Structures
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
|STRUCTURE | DEFINITION | |STRUCTURE | DEFINITION |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| if | If x is true then return y else return z. | | if | If x is true then return y else return z. |
| | (eg: if(x, y, z) or if((x + 1) > 2y, z + 1, w / v)) | | | (eg: if(x, y, z) or if((x + 1) > 2y, z + 1, w / v)) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| switch | The first true case condition that is encountered will | | switch | The first true case condition that is encountered will |
| | determine the result of the switch. If none of the case | | | determine the result of the switch. If none of the case |
| | conditions hold true, the default action is assumed as | | | conditions hold true, the default action is assumed as |
@ -346,7 +356,7 @@ include path (e.g: /usr/include/).
| | case x < 3 : sin(x + y) | | | case x < 3 : sin(x + y) |
| | default : 1 + x; | | | default : 1 + x; |
| | } | | | } |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| while | The structure will repeatedly evaluate the internal | | while | The structure will repeatedly evaluate the internal |
| | statement(s) 'while' the condition is true. The final | | | statement(s) 'while' the condition is true. The final |
| | statement in the final iteration will be used as the | | | statement in the final iteration will be used as the |
@ -357,7 +367,7 @@ include path (e.g: /usr/include/).
| | y := x + z; | | | y := x + z; |
| | w := z + y; | | | w := z + y; |
| | } | | | } |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| repeat/ | The structure will repeatedly evaluate the internal | | repeat/ | The structure will repeatedly evaluate the internal |
| until | statement(s) 'until' the condition is true. The final | | until | statement(s) 'until' the condition is true. The final |
| | statement in the final iteration will be used as the | | | statement in the final iteration will be used as the |
@ -367,14 +377,14 @@ include path (e.g: /usr/include/).
| | y := x + z; | | | y := x + z; |
| | w := z + y; | | | w := z + y; |
| | until ((x := (x - 1)) <= 0) | | | until ((x := (x - 1)) <= 0) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
| ~ | Evaluate each sub-expression, then return as the result | | ~ | Evaluate each sub-expression, then return as the result |
| | the value of the last sub-expression. This is sometimes | | | the value of the last sub-expression. This is sometimes |
| | known as multiple sequence point evaluation. | | | known as multiple sequence point evaluation. |
| | eg: | | | eg: |
| | ~(i := x + 1, j := y / z, k := sin(w/u)) == (sin(w/u))) | | | ~(i := x + 1, j := y / z, k := sin(w/u)) == (sin(w/u))) |
| | ~{i := x + 1; j := y / z; k := sin(w/u)} == (sin(w/u))) | | | ~{i := x + 1; j := y / z; k := sin(w/u)} == (sin(w/u))) |
+-----------+--------------------------------------------------------+ +----------+---------------------------------------------------------+
@ -382,7 +392,7 @@ include path (e.g: /usr/include/).
The purpose of special functions in ExprTk is to provide compiler The purpose of special functions in ExprTk is to provide compiler
generated equivalents of common mathematical expressions which can be generated equivalents of common mathematical expressions which can be
invoked by using the 'special function' syntax (eg: $f12(x,y,z) or invoked by using the 'special function' syntax (eg: $f12(x,y,z) or
$f24(x,y,z,w)). $f82(x,y,z,w)).
Special functions dramatically decrease the total evaluation time of Special functions dramatically decrease the total evaluation time of
expressions which would otherwise have been written using the common expressions which would otherwise have been written using the common
@ -466,7 +476,8 @@ correctly optimize such expressions for a given architecture.
(A-Z or a-z), then can be comprised of any combination of (A-Z or a-z), then can be comprised of any combination of
letters, digits and underscores. (eg: x, var1 or power_func99) letters, digits and underscores. (eg: x, var1 or power_func99)
(06) Expression lengths are limited only by storage capacity. (06) Expression lengths and sub-expression lists are limited only by
storage capacity.
(07) The life-time of objects registered with or created from a (07) The life-time of objects registered with or created from a
specific symbol-table must span at least the life-time of specific symbol-table must span at least the life-time of
@ -487,7 +498,7 @@ correctly optimize such expressions for a given architecture.
(11) Strings may be constructed from any letters, digits or special (11) Strings may be constructed from any letters, digits or special
characters such as (~!@#$%^&*()[]|=+ ,./?<>;:"`~_), and must characters such as (~!@#$%^&*()[]|=+ ,./?<>;:"`~_), and must
be enclosed with single-quotes. be enclosed with single-quotes.
eg: 'Frankly, my dear, I don't give a damn!' eg: 'Frankly, my dear, I do not give a damn!'
(12) User defined normal functions can have up to 20 parameters, (12) User defined normal functions can have up to 20 parameters,
where as user defined vararg-functions can have an unlimited where as user defined vararg-functions can have an unlimited
@ -505,7 +516,10 @@ correctly optimize such expressions for a given architecture.
(16) Composited functions can call themselves or any other functions (16) Composited functions can call themselves or any other functions
that have been defined prior to their own definition. that have been defined prior to their own definition.
(17) Expressions may contain any of the following comment styles: (17) Recursive calls made from within composited functions will have
a stack size bound by the stack of executing architecture.
(18) Expressions may contain any of the following comment styles:
1. // .... \n 1. // .... \n
2. # .... \n 2. # .... \n
3. /* .... */ 3. /* .... */