C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
806c519c91
commit
f46bffcd69
|
@ -1,18 +1,18 @@
|
|||
version: 2.1
|
||||
jobs:
|
||||
|
||||
build_gcc_6:
|
||||
build_gcc_09:
|
||||
docker:
|
||||
- image: gcc:6
|
||||
- image: gcc:9
|
||||
steps:
|
||||
- checkout
|
||||
- run: c++ --version
|
||||
- run: make all -j 2
|
||||
- run: ./exprtk_test
|
||||
|
||||
build_gcc_7:
|
||||
build_gcc_10:
|
||||
docker:
|
||||
- image: gcc:7
|
||||
- image: gcc:10
|
||||
steps:
|
||||
- checkout
|
||||
- run: c++ --version
|
||||
|
@ -32,6 +32,6 @@ workflows:
|
|||
version: 2
|
||||
build_and_test:
|
||||
jobs:
|
||||
- build_gcc_6
|
||||
- build_gcc_7
|
||||
- build_gcc_09
|
||||
- build_gcc_10
|
||||
- build_gcc_latest
|
||||
|
|
4
Makefile
4
Makefile
|
@ -2,8 +2,8 @@
|
|||
# **************************************************************
|
||||
# * C++ Mathematical Expression Toolkit Library *
|
||||
# * *
|
||||
# * Author: Arash Partow (1999-2022) *
|
||||
# * URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
# * Author: Arash Partow (1999-2023) *
|
||||
# * URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
# * *
|
||||
# * Copyright notice: *
|
||||
# * Free use of the Mathematical Expression Toolkit Library is *
|
||||
|
|
1582
exprtk.hpp
1582
exprtk.hpp
File diff suppressed because it is too large
Load Diff
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* ExprTk vs Native Benchmarks *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
@ -361,8 +361,6 @@ int main(int argc, char* argv[])
|
|||
|
||||
double pgo_primer()
|
||||
{
|
||||
exprtk::pgo_primer<double>();
|
||||
|
||||
static const double lower_bound_x = -50.0;
|
||||
static const double lower_bound_y = -50.0;
|
||||
static const double upper_bound_x = +50.0;
|
||||
|
|
|
@ -8303,4 +8303,8 @@ equal(true,~{var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; ((1 > 2) ? v0 - v1 :
|
|||
equal(true,~{var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x_ := 1; var y_ := 2; ((x_ < y_) ? v0 : v1) == v0})
|
||||
equal(true,~{var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x_ := 1; var y_ := 2; ((x_ > y_) ? v0 : v1) == v1})
|
||||
equal(true,~{var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x_ := 1; var y_ := 2; ((x_ < y_) ? v0 - v1 : v1 - v0) == (v0 - v1)})
|
||||
equal(true,~{var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x_ := 1; var y_ := 2; ((x_ > y_) ? v0 - v1 : v1 - v0) == (v1 - v0)})
|
||||
equal(true,~{var v0[3] := {1,2,3}; var v1[4] := {6,7,8,9}; var x_ := 1; var y_ := 2; ((x_ > y_) ? v0 - v1 : v1 - v0) == (v1 - v0)})
|
||||
equal(true,~{var xx := 0; for(var i:= 0; i < 10; i+=1) { for(var j:= 0; j < 100; j+=1) { if (j > i) break; xx += 1; } }; xx == 55})
|
||||
equal(true,~{var xx := 0; for(var i:= 0; i < 10; i+=1) { for(var j:= 0; j < 100; j+=1) { xx += 1; if (j > i) break; } }; xx == 65})
|
||||
equal(true,~{var xx := 0; var i := 0; while(i < 10) { var j := 0; while(j < 100) { if (j > i) break; xx += 1; j+=1 }; i+=1 }; xx == 55})
|
||||
equal(true,~{var xx := 0; var i := 0; while(i < 10) { var j := 0; while(j < 100) { xx += 1; if (j > i) break; j+=1 }; i+=1 }; xx == 65})
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 1 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 2 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 3 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 4 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 5 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 6 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 7 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 8 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 9 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 10 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 11 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 12 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 13 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 14 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 15 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 16 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 17 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 18 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 19 *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
|
130
exprtk_test.cpp
130
exprtk_test.cpp
|
@ -3,14 +3,14 @@
|
|||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Examples and Unit-Tests *
|
||||
* Author: Arash Partow (1999-2022) *
|
||||
* URL: http://www.partow.net/programming/exprtk/index.html *
|
||||
* Author: Arash Partow (1999-2023) *
|
||||
* URL: https://www.partow.net/programming/exprtk/index.html *
|
||||
* *
|
||||
* Copyright notice: *
|
||||
* Free use of the Mathematical Expression Toolkit Library is *
|
||||
* permitted under the guidelines and in accordance with the *
|
||||
* most current version of the MIT License. *
|
||||
* http://www.opensource.org/licenses/MIT *
|
||||
* https://www.opensource.org/licenses/MIT *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
@ -5072,12 +5072,6 @@ inline bool run_test11()
|
|||
}
|
||||
}
|
||||
|
||||
if (!exprtk::pgo_primer<T>())
|
||||
{
|
||||
printf("run_test11() - Failed PGO primer\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -7206,7 +7200,7 @@ inline bool run_test18()
|
|||
{
|
||||
v.rebase(v0.data() + i);
|
||||
|
||||
T sum = expression.value();
|
||||
const T sum = expression.value();
|
||||
|
||||
if (not_equal(sum,s[i]))
|
||||
{
|
||||
|
@ -7259,7 +7253,7 @@ inline bool run_test18()
|
|||
return false;
|
||||
}
|
||||
|
||||
const T expected_result0 = std::accumulate(v0, v0 + v0_size,T(0));
|
||||
const T expected_result0 = std::accumulate(v0, v0 + v0_size, T(0));
|
||||
|
||||
if (expression.value() != expected_result0)
|
||||
{
|
||||
|
@ -7273,7 +7267,7 @@ inline bool run_test18()
|
|||
|
||||
v.rebase(v1);
|
||||
|
||||
const T expected_result1 = std::accumulate(v1, v1 + v1_size,T(0));
|
||||
const T expected_result1 = std::accumulate(v1, v1 + v1_size, T(0));
|
||||
|
||||
if (expression.value() != expected_result1)
|
||||
{
|
||||
|
@ -8436,7 +8430,7 @@ inline bool run_test19()
|
|||
|
||||
const T result = expression.value();
|
||||
|
||||
if (not_equal(result,std::sqrt(x),T(0.0000001)))
|
||||
if (not_equal(result, std::sqrt(x), T(0.0000001)))
|
||||
{
|
||||
printf("run_test19() - Computation Error "
|
||||
"Expression: [%s]\tExpected: %12.8f\tResult: %12.8f\n",
|
||||
|
@ -9060,17 +9054,17 @@ inline bool run_test21()
|
|||
typedef exprtk::expression<T> expression_t;
|
||||
typedef exprtk::parser<T> parser_t;
|
||||
|
||||
T x = T(1.1);
|
||||
T y = T(2.2);
|
||||
T z = T(3.3);
|
||||
|
||||
symbol_table_t symbol_table;
|
||||
symbol_table.add_constants();
|
||||
symbol_table.add_variable("x",x);
|
||||
symbol_table.add_variable("y",y);
|
||||
symbol_table.add_variable("z",z);
|
||||
|
||||
{
|
||||
T x = T(1.1);
|
||||
T y = T(2.2);
|
||||
T z = T(3.3);
|
||||
|
||||
symbol_table_t symbol_table;
|
||||
symbol_table.add_constants();
|
||||
symbol_table.add_variable("x",x);
|
||||
symbol_table.add_variable("y",y);
|
||||
symbol_table.add_variable("z",z);
|
||||
|
||||
static const std::string expression_list[] =
|
||||
{
|
||||
"return[]; x;",
|
||||
|
@ -9169,6 +9163,16 @@ inline bool run_test21()
|
|||
}
|
||||
|
||||
{
|
||||
T x = T(1.1);
|
||||
T y = T(2.2);
|
||||
T z = T(3.3);
|
||||
|
||||
symbol_table_t symbol_table;
|
||||
symbol_table.add_constants();
|
||||
symbol_table.add_variable("x",x);
|
||||
symbol_table.add_variable("y",y);
|
||||
symbol_table.add_variable("z",z);
|
||||
|
||||
static const std::string expression_list[] =
|
||||
{
|
||||
"x := 1; x + 1; x + 2; x + 3; x + 5; x + 7; return [x + 1]; ",
|
||||
|
@ -9260,6 +9264,86 @@ inline bool run_test21()
|
|||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
const std::string invalid_expressions[] =
|
||||
{
|
||||
"x := 1",
|
||||
"x += 1",
|
||||
"v := 1 + v",
|
||||
"v += 1",
|
||||
"v += x + 1",
|
||||
"v += v",
|
||||
"v[0] += x",
|
||||
"v[1] += x",
|
||||
"v[2] += x",
|
||||
"v[3] += x",
|
||||
"v[4] += x",
|
||||
"var i := 2; v[i] := x",
|
||||
"var i := 2; v[i] += x",
|
||||
"s := 'abc' + s",
|
||||
"s[0:2] := 'abc'",
|
||||
"s[1:3] := 'abc'",
|
||||
"aa[4:4] := bb",
|
||||
"aa[1:3] := bb",
|
||||
"var i := 2; aa[i:3] := bb",
|
||||
"var i := 2; aa[i+1:3] := bb",
|
||||
"var i := 2; aa[0:i] := bb",
|
||||
"var i := 2; aa[0:i+1] := bb",
|
||||
"var i := 1; var j := 3; aa[i:j] := bb",
|
||||
"var i := 1; var j := 3; aa[i+1:j] := bb",
|
||||
"var i := 1; var j := 3; aa[i:j+1] := bb",
|
||||
"var i := 1; var j := 3; aa[i+1:j+1] := bb",
|
||||
};
|
||||
|
||||
const std::size_t invalid_expressions_size = sizeof(invalid_expressions) / sizeof(std::string);
|
||||
|
||||
for (std::size_t i = 0; i < invalid_expressions_size; ++i)
|
||||
{
|
||||
symbol_table_t mutable_symbol_table;
|
||||
symbol_table_t immutable_symbol_table(symbol_table_t::e_immutable);
|
||||
|
||||
T x = 0.0;
|
||||
T v[5];
|
||||
std::string s = "xyz";
|
||||
std::string aa = "0123456789";
|
||||
std::string bb = "A";
|
||||
|
||||
T x_ = 0.0;
|
||||
T v_[5];
|
||||
std::string s_ = "xyz";
|
||||
|
||||
std::string a_ = "0123456789";
|
||||
std::string b_ = "A";
|
||||
|
||||
immutable_symbol_table.add_variable ("x" , x );
|
||||
immutable_symbol_table.add_vector ("v" , v );
|
||||
immutable_symbol_table.add_stringvar("s" , s );
|
||||
immutable_symbol_table.add_stringvar("aa", aa);
|
||||
immutable_symbol_table.add_stringvar("bb", bb);
|
||||
|
||||
mutable_symbol_table.add_variable ("x_", x_);
|
||||
mutable_symbol_table.add_vector ("v_", v_);
|
||||
mutable_symbol_table.add_stringvar ("s_", s_);
|
||||
mutable_symbol_table.add_stringvar ("a_", a_);
|
||||
mutable_symbol_table.add_stringvar ("b_", b_);
|
||||
|
||||
const std::string& expression_str = invalid_expressions[i];
|
||||
expression_t expression;
|
||||
expression.register_symbol_table(immutable_symbol_table);
|
||||
expression.register_symbol_table(mutable_symbol_table );
|
||||
|
||||
parser_t parser;
|
||||
const bool compile_result = parser.compile(expression_str, expression);
|
||||
|
||||
if (compile_result)
|
||||
{
|
||||
expression.value();
|
||||
printf("run_test21() - Invalid expression due to immutability was successfully compiled. Expression: %s\n",
|
||||
expression_str.c_str());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
166
readme.txt
166
readme.txt
|
@ -115,7 +115,7 @@ 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.
|
||||
|
||||
http://www.opensource.org/licenses/MIT
|
||||
https://www.opensource.org/licenses/MIT
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
|
@ -707,7 +707,7 @@ the expression instance and to also allow the expression to be
|
|||
evaluated using the current value of the element.
|
||||
|
||||
Note: Any variable reference provided to a given symbol_table
|
||||
instance, must have a life time at least as long as the life-time of
|
||||
instance, must have a life-time at least as long as the life-time of
|
||||
the symbol_table instance. In the event the variable reference is
|
||||
invalidated before the symbol_table or any dependent expression
|
||||
instances have been destructed, then any associated expression
|
||||
|
@ -868,6 +868,66 @@ a false result due to one or more of the following reasons:
|
|||
6. The symbol_table instance is in an invalid state
|
||||
|
||||
|
||||
A further property of symbol tables is that they can be classified at
|
||||
instantiation as either being mutable (by default) or immutable. The
|
||||
following demonstrates construction of an immutable symbol table
|
||||
instance:
|
||||
|
||||
symbol_table_t immutable_symbol_table
|
||||
(symbol_table_t::symtab_mutability_type::e_immutable);
|
||||
|
||||
|
||||
When a symbol table, that has been constructed as being immutable, is
|
||||
registered with an expression, any statements in the expression string
|
||||
that modify the variables that are managed by the immutable symbol
|
||||
table will result in a compilation error. The operations that trigger
|
||||
the mutability constraint are the following assignment operators:
|
||||
|
||||
1. Assignment: :=
|
||||
2. Assign operation: +=, -=, *=, /= , %=
|
||||
|
||||
|
||||
The main reason for this functionality is that, one may want the
|
||||
immutability properties that come with constness of a variable such as
|
||||
scalars, vectors and strings, but not necessarily the accompanying
|
||||
compile time const-folding optimisations, that would result in the
|
||||
value of the variables being retrieved only once at compile time,
|
||||
causing external updates to the variables to not be part of the
|
||||
expression evaluation.
|
||||
|
||||
symbol_table_t immutable_symbol_table
|
||||
(symbol_table_t::symtab_mutability_type::e_immutable);
|
||||
|
||||
T x = 0.0;
|
||||
|
||||
const std::string expression_str = "x + (y + y)";
|
||||
|
||||
immutable_symbol_table.add_variable("x" , x );
|
||||
immutable_symbol_table.add_constant("y" , 123.0);
|
||||
|
||||
expression_t expression;
|
||||
expression.register_symbol_table(immutabile_symbol_table);
|
||||
|
||||
parser_t parser;
|
||||
parser.compile(expression_str, expression)
|
||||
|
||||
for (; x < 10.0; ++x)
|
||||
{
|
||||
const auto expected_value = x + (123.0 + 123.0);
|
||||
const auto result_value = expression.value();
|
||||
assert(expression.value() != expected_value);
|
||||
}
|
||||
|
||||
|
||||
In the above example, there are two variables X and Y. Where Y is a
|
||||
constant and X is a normal variable. Both are registered with a symbol
|
||||
table that is immutable. The expression when compiled will result in
|
||||
the "(y + y)" part being const-folded at compile time to the literal
|
||||
value of 246. Whereas the current value of X, being updated via the
|
||||
for-loop, externally to the expression and the symbol table will be
|
||||
available to the expression upon each evaluation.
|
||||
|
||||
|
||||
(2) Expression
|
||||
A structure that holds an Abstract Syntax Tree or AST for a specified
|
||||
expression and is used to evaluate said expression. Evaluation of the
|
||||
|
@ -1020,7 +1080,7 @@ may include user defined variables or functions. These are embedded as
|
|||
references into the expression's AST. When copying an expression, said
|
||||
references need to also be copied. If the references are blindly
|
||||
copied, it will then result in two or more identical expressions
|
||||
utilizing the exact same references for variables. This obviously is
|
||||
utilising the exact same references for variables. This obviously is
|
||||
not the default assumed scenario and will give rise to non-obvious
|
||||
behaviours when using the expressions in various contexts such as
|
||||
multi-threading et al.
|
||||
|
@ -1110,6 +1170,7 @@ enabled by default. The options and their explanations are as follows:
|
|||
(5) Sequence Check
|
||||
(6) Commutative Check
|
||||
(7) Strength Reduction Check
|
||||
(8) Stack And Node Depth Check
|
||||
|
||||
|
||||
(1) Replacer (e_replacer)
|
||||
|
@ -1218,6 +1279,43 @@ desired over the strength reduced form. In these situations it is best
|
|||
to turn off strength reduction optimisations or to use a type with a
|
||||
larger numerical bound.
|
||||
|
||||
|
||||
(8) Stack And Node Depth Check
|
||||
ExprTk incorporates a recursive descent parser. When parsing
|
||||
expressions comprising inner sub-expressions, the recursive nature of
|
||||
the parsing process causes the stack to grow. If the expression causes
|
||||
the stack to grow beyond the stack size limit, this would lead to a
|
||||
stackoverflow and its associated stack corruption and security
|
||||
vulnerability issues.
|
||||
|
||||
Similarly to parsing, evaluating an expression may cause the stack to
|
||||
grow. Such things like user defined functions, composite functions and
|
||||
the general nature of the AST being evaluated can cause the stack to
|
||||
grow, and may result in potential stackoverflow issues as denoted
|
||||
above.
|
||||
|
||||
ExprTk provides a set of checks that prevent both of the above denoted
|
||||
problems at compile time. These check rely on two specific limits
|
||||
being set on the parser instance, these limits are:
|
||||
|
||||
1. max_stack_depth (default: 400)
|
||||
2. max_node_depth (default: 10000)
|
||||
|
||||
|
||||
The following demonstrates how these two parser parameters can be set:
|
||||
|
||||
parser_t parser;
|
||||
|
||||
parser.set_max_stack_depth(100);
|
||||
parser.set_max_node_depth(200);
|
||||
|
||||
|
||||
In the above code, during parsing if the stack depth reaches or
|
||||
exceeds 100 levels, the parsing process will immediately halt and
|
||||
return with a failure. Similarly, during synthesizing the AST nodes,
|
||||
if the compilation process detects an AST tree depth exceeding 200
|
||||
levels the parsing process will halt and return a parsing failure.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
[SECTION 12 - EXPRESSION STRUCTURES]
|
||||
|
@ -1780,7 +1878,7 @@ value is not a vector but rather a single value.
|
|||
sum(x > 0 and x < 5) == x[]
|
||||
|
||||
|
||||
When utilizing external user defined vectors via the symbol table as
|
||||
When utilising external user defined vectors via the symbol table as
|
||||
opposed to expression local defined vectors, the typical 'add_vector'
|
||||
method from the symbol table will register the entirety of the vector
|
||||
that is passed. The following example attempts to evaluate the sum of
|
||||
|
@ -3489,7 +3587,7 @@ ExprTk reserved words, the add_function call will fail.
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
[SECTION 20 - EXPRESSION RETURN VALUES]
|
||||
ExprTk expressions can return immediately from any point by utilizing
|
||||
ExprTk expressions can return immediately from any point by utilising
|
||||
the return call. Furthermore the return call can be used to transfer
|
||||
out multiple return values from within the expression.
|
||||
|
||||
|
@ -4591,52 +4689,58 @@ part of a compiler command line switch or scoped around the include to
|
|||
the ExprTk header. The defines are as follows:
|
||||
|
||||
(01) exprtk_enable_debugging
|
||||
(02) exprtk_disable_comments
|
||||
(03) exprtk_disable_break_continue
|
||||
(04) exprtk_disable_sc_andor
|
||||
(05) exprtk_disable_return_statement
|
||||
(06) exprtk_disable_enhanced_features
|
||||
(07) exprtk_disable_string_capabilities
|
||||
(08) exprtk_disable_superscalar_unroll
|
||||
(09) exprtk_disable_rtl_io_file
|
||||
(10) exprtk_disable_rtl_vecops
|
||||
(11) exprtk_disable_caseinsensitivity
|
||||
|
||||
(02) exprtk_disable_cardinal_pow_optimisation
|
||||
(03) exprtk_disable_comments
|
||||
(04) exprtk_disable_break_continue
|
||||
(05) exprtk_disable_sc_andor
|
||||
(06) exprtk_disable_return_statement
|
||||
(07) exprtk_disable_enhanced_features
|
||||
(08) exprtk_disable_string_capabilities
|
||||
(09) exprtk_disable_superscalar_unroll
|
||||
(10) exprtk_disable_rtl_io
|
||||
(11) exprtk_disable_rtl_io_file
|
||||
(12) exprtk_disable_rtl_vecops
|
||||
(13) exprtk_disable_caseinsensitivity
|
||||
(14) exprtk_enable_range_runtime_checks
|
||||
|
||||
(01) exprtk_enable_debugging
|
||||
This define will enable printing of debug information to stdout during
|
||||
the compilation process.
|
||||
|
||||
(02) exprtk_disable_comments
|
||||
(02) exprtk_disable_cardinal_pow_optimisation
|
||||
This define will disable the optimisation invoked when constant
|
||||
integers are used as powers in exponentiation expressions (eg: x^7).
|
||||
|
||||
(03) exprtk_disable_comments
|
||||
This define will disable the ability for expressions to have comments.
|
||||
Expressions that have comments when parsed with a build that has this
|
||||
option, will result in a compilation failure.
|
||||
|
||||
(03) exprtk_disable_break_continue
|
||||
(04) exprtk_disable_break_continue
|
||||
This define will disable the loop-wise 'break' and 'continue'
|
||||
capabilities. Any expression that contains those keywords will result
|
||||
in a compilation failure.
|
||||
|
||||
(04) exprtk_disable_sc_andor
|
||||
(05) exprtk_disable_sc_andor
|
||||
This define will disable the short-circuit '&' (and) and '|' (or)
|
||||
operators
|
||||
|
||||
(05) exprtk_disable_return_statement
|
||||
(06) exprtk_disable_return_statement
|
||||
This define will disable use of return statements within expressions.
|
||||
|
||||
(06) exprtk_disable_enhanced_features
|
||||
(07) exprtk_disable_enhanced_features
|
||||
This define will disable all enhanced features such as strength
|
||||
reduction and special function optimisations and expression specific
|
||||
type instantiations. This feature will reduce compilation times and
|
||||
binary sizes but will also result in massive performance degradation
|
||||
of expression evaluations.
|
||||
|
||||
(07) exprtk_disable_string_capabilities
|
||||
(08) exprtk_disable_string_capabilities
|
||||
This define will disable all string processing capabilities. Any
|
||||
expression that contains a string or string related syntax will result
|
||||
in a compilation failure.
|
||||
|
||||
(08) exprtk_disable_superscalar_unroll
|
||||
(09) exprtk_disable_superscalar_unroll
|
||||
This define will set the loop unroll batch size to 4 operations per
|
||||
loop instead of the default 8 operations. This define is used in
|
||||
operations that involve vectors and aggregations over vectors. When
|
||||
|
@ -4644,22 +4748,32 @@ targeting non-superscalar architectures, it may be recommended to
|
|||
build using this particular option if efficiency of evaluations is of
|
||||
concern.
|
||||
|
||||
(09) exprtk_disable_rtl_io_file
|
||||
(10) exprtk_disable_rtl_io
|
||||
This define will disable all of basic IO RTL package features. When
|
||||
present, any attempt to register the basic IO RTL package with a given
|
||||
symbol table will fail causing a compilation error.
|
||||
|
||||
(11) exprtk_disable_rtl_io_file
|
||||
This define will disable the file I/O RTL package features. When
|
||||
present, any attempts to register the file I/O package with a given
|
||||
symbol table will fail causing a compilation error.
|
||||
|
||||
(10) exprtk_disable_rtl_vecops
|
||||
(12) exprtk_disable_rtl_vecops
|
||||
This define will disable the extended vector operations RTL package
|
||||
features. When present, any attempts to register the vector operations
|
||||
package with a given symbol table will fail causing a compilation
|
||||
error.
|
||||
|
||||
(11) exprtk_disable_caseinsensitivity
|
||||
(13) exprtk_disable_caseinsensitivity
|
||||
This define will disable case-insensitivity when matching variables
|
||||
and functions. Furthermore all reserved and keywords will only be
|
||||
acknowledged when in all lower-case.
|
||||
|
||||
(14) exprtk_enable_range_runtime_checks
|
||||
This define will enable run-time checks pertaining to vector indexing
|
||||
operations used in any of the vector-to-vector and vector-to-scalar
|
||||
operations.
|
||||
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
[SECTION 28 - FILES]
|
||||
|
|
Loading…
Reference in New Issue