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

This commit is contained in:
Arash Partow 2021-01-01 00:00:00 +00:00 committed by ArashPartow
parent c7c219480d
commit 7135f4ddb1
24 changed files with 1849 additions and 1424 deletions

View File

@ -6,6 +6,7 @@ jobs:
- image: gcc:6
steps:
- checkout
- run: c++ --version
- run: make all -j 2
- run: ./exprtk_test
@ -14,6 +15,7 @@ jobs:
- image: gcc:7
steps:
- checkout
- run: c++ --version
- run: make all -j 2
- run: ./exprtk_test
@ -22,6 +24,7 @@ jobs:
- image: gcc:latest
steps:
- checkout
- run: c++ --version
- run: make all -j 2
- run: ./exprtk_test

View File

@ -2,7 +2,7 @@
# **************************************************************
# * C++ Mathematical Expression Toolkit Library *
# * *
# * Author: Arash Partow (1999-2020) *
# * Author: Arash Partow (1999-2021) *
# * URL: http://www.partow.net/programming/exprtk/index.html *
# * *
# * Copyright notice: *

2731
exprtk.hpp

File diff suppressed because it is too large Load Diff

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* ExprTk vs Native Benchmarks *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 1 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 2 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 3 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 4 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 5 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 6 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 7 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 8 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 9 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 10 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 11 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 12 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 13 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 14 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 15 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 16 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 17 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 18 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Simple Example 19 *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *

View File

@ -3,7 +3,7 @@
* C++ Mathematical Expression Toolkit Library *
* *
* Examples and Unit-Tests *
* Author: Arash Partow (1999-2020) *
* Author: Arash Partow (1999-2021) *
* URL: http://www.partow.net/programming/exprtk/index.html *
* *
* Copyright notice: *
@ -358,6 +358,42 @@ static const test_t global_test_list[] =
test_t("( 7 - 2 )",+5.0),
test_t("( 8 - 1 )",+7.0),
test_t("( 9 - 0 )",+9.0),
test_t("1 - -1" , 2.0),
test_t("1 --1" , 2.0),
test_t("1-- 1" , 2.0),
test_t("1--1" , 2.0),
test_t("1 -- -1", 0.0),
test_t("1 + -1" , 0.0),
test_t("1 +-1" , 0.0),
test_t("1+- 1" , 0.0),
test_t("1+-1" , 0.0),
test_t("1 +- -1", 2.0),
test_t("1 + +1" , 2.0),
test_t("1 ++1" , 2.0),
test_t("1 - -1 + 1" , 3.0),
test_t("1 --1 + 1" , 3.0),
test_t("1-- 1 + 1" , 3.0),
test_t("1--1 + 1" , 3.0),
test_t("1 -- -1 + 1", 1.0),
test_t("1 + -1 + 1" , 1.0),
test_t("1 +-1 + 1" , 1.0),
test_t("1+- 1 + 1" , 1.0),
test_t("1+-1 + 1" , 1.0),
test_t("1 +- -1 + 1", 3.0),
test_t("1 + +1 + 1" , 3.0),
test_t("1 ++1 + 1" , 3.0),
test_t("1 - -1 - 1" , 1.0),
test_t("1 --1 - 1" , 1.0),
test_t("1-- 1 - 1" , 1.0),
test_t("1--1 - 1" , 1.0),
test_t("1 -- -1 - 1", -1.0),
test_t("1 + -1 - 1" , -1.0),
test_t("1 +-1 - 1" , -1.0),
test_t("1+- 1 - 1" , -1.0),
test_t("1+-1 - 1" , -1.0),
test_t("1 +- -1 - 1", 1.0),
test_t("1 + +1 - 1" , 1.0),
test_t("1 ++1 - 1" , 1.0),
test_t("-(1+2)",-3.0),
test_t("+(1+2)",+3.0),
test_t("+(1-2)",-1.0),
@ -1162,14 +1198,14 @@ inline bool test_expression(const std::string& expression_string, const T& expec
return false;
}
T result = expression.value();
const T result = expression.value();
if (not_equal(result,expected_result))
{
printf("test_expression() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n",
expression_string.c_str(),
(double)expected_result,
(double)result);
static_cast<double>(expected_result),
static_cast<double>(result));
return false;
}
@ -1177,6 +1213,43 @@ inline bool test_expression(const std::string& expression_string, const T& expec
return true;
}
template <typename T>
struct edge_cases {};
template <>
struct edge_cases<float>
{
static inline std::vector<test_t> test_cases()
{
std::vector<test_t> cases;
cases.push_back(test_t(" 1.175494350822287508e-38", 1.175494350822287508e-38));
cases.push_back(test_t(" 3.402823466385288598e+38", 3.402823466385288598e+38));
cases.push_back(test_t("+1.175494350822287508e-38", +1.175494350822287508e-38));
cases.push_back(test_t("+3.402823466385288598e+38", +3.402823466385288598e+38));
cases.push_back(test_t("-1.175494350822287508e-38", -1.175494350822287508e-38));
cases.push_back(test_t("-3.402823466385288598e+38", -3.402823466385288598e+38));
return cases;
}
};
template <>
struct edge_cases<double>
{
static inline std::vector<test_t> test_cases()
{
std::vector<test_t> cases;
cases.push_back(test_t(" 2.2250738585072013831e-308", 2.2250738585072013831e-308));
cases.push_back(test_t(" 1.7976931348623157081e+308", 1.7976931348623157081e+308));
cases.push_back(test_t("+2.2250738585072013831e-308", +2.2250738585072013831e-308));
cases.push_back(test_t("+1.7976931348623157081e+308", +1.7976931348623157081e+308));
cases.push_back(test_t("-2.2250738585072013831e-308", -2.2250738585072013831e-308));
cases.push_back(test_t("-1.7976931348623157081e+308", -1.7976931348623157081e+308));
return cases;
}
};
template <typename T>
inline bool run_test00()
{
@ -1198,6 +1271,25 @@ inline bool run_test00()
}
}
{
const std::vector<test_t> tests = edge_cases<T>::test_cases();
bool result = true;
for (std::size_t i = 0; i < tests.size(); ++i)
{
if (!test_expression<T>(tests[i].first,T(tests[i].second)))
{
result = false;
}
}
if (!result)
{
return false;
}
}
return true;
}
@ -1256,34 +1348,106 @@ inline bool run_test01()
test_xy<T>("2 * (x + y) - 1" ,T(2.2),T(3.3),T(10.0 )),
test_xy<T>("y + (x + 1)" ,T(2.2),T(3.3),T(6.5 )),
test_xy<T>("(x + 1) + y" ,T(2.2),T(3.3),T(6.5 )),
test_xy<T>("2 * x" ,T(2.2),T(0.0),T(4.4)),
test_xy<T>("x * 2" ,T(2.2),T(0.0),T(4.4)),
test_xy<T>("1.1 + x",T(2.2),T(0.0),T(3.3)),
test_xy<T>("x + 1.1",T(2.2),T(0.0),T(3.3)),
test_xy<T>("x * 1 == x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("1 * x == x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y * 1 == y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("1 * y == y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * 0 == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("0 * x == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y * 0 == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("0 * y == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + 1 == 1 + x",T(2.0),T(3.0),T(1.0)),
test_xy<T>("y + 1 == 1 + y",T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + y == y + x",T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * y == y * x",T(2.0),T(3.0),T(1.0)),
test_xy<T>("x < y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x <= y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y >= x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + y > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + y > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * y > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * y > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x + y) > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x + y) > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x * y) > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x * y) > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("2 * x" ,T(2.2),T(0.0),T(4.4)),
test_xy<T>("x * 2" ,T(2.2),T(0.0),T(4.4)),
test_xy<T>("1.1 + x" ,T(2.2),T(0.0),T(3.3)),
test_xy<T>("x + 1.1" ,T(2.2),T(0.0),T(3.3)),
test_xy<T>("x - -1 " ,T(1.0),T(0.0),T(2)),
test_xy<T>("x --1 " ,T(1.0),T(0.0),T(2)),
test_xy<T>("x-- 1 " ,T(1.0),T(0.0),T(2)),
test_xy<T>("x--1 " ,T(1.0),T(0.0),T(2)),
test_xy<T>("x -- -1" ,T(1.0),T(0.0),T(0)),
test_xy<T>("x + -1 " ,T(1.0),T(0.0),T(0)),
test_xy<T>("x +-1 " ,T(1.0),T(0.0),T(0)),
test_xy<T>("x+- 1 " ,T(1.0),T(0.0),T(0)),
test_xy<T>("x+-1 " ,T(1.0),T(0.0),T(0)),
test_xy<T>("x +- -1" ,T(1.0),T(0.0),T(2)),
test_xy<T>("x + +1 " ,T(1.0),T(0.0),T(2)),
test_xy<T>("x ++1 " ,T(1.0),T(0.0),T(2)),
test_xy<T>("1 - -x " ,T(1.0),T(0.0),T(2)),
test_xy<T>("1 --x " ,T(1.0),T(0.0),T(2)),
test_xy<T>("1-- x " ,T(1.0),T(0.0),T(2)),
test_xy<T>("1--x " ,T(1.0),T(0.0),T(2)),
test_xy<T>("1 -- -x" ,T(1.0),T(0.0),T(0)),
test_xy<T>("1 + -x " ,T(1.0),T(0.0),T(0)),
test_xy<T>("1 +-x " ,T(1.0),T(0.0),T(0)),
test_xy<T>("1+- x " ,T(1.0),T(0.0),T(0)),
test_xy<T>("1+-x " ,T(1.0),T(0.0),T(0)),
test_xy<T>("1 +- -x" ,T(1.0),T(0.0),T(2)),
test_xy<T>("1 + +x " ,T(1.0),T(0.0),T(2)),
test_xy<T>("1 ++x " ,T(1.0),T(0.0),T(2)),
test_xy<T>("(x - -1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x --1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x-- 1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x--1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x -- -1 + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x + -1 + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x +-1 + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x+- 1 + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x+-1 + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x +- -1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x + +1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x ++1 + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1 - -x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1 --x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1-- x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1--x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1 -- -x + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 + -x + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 +-x + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1+- x + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1+-x + 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 +- -x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1 + +x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(1 ++x + 1)" ,T(1.0),T(0.0),T(3)),
test_xy<T>("(x - -1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x --1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x-- 1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x--1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x -- -1 - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(x + -1 - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(x +-1 - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(x+- 1 - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(x+-1 - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(x +- -1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x + +1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(x ++1 - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 - -x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 --x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1-- x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1--x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 -- -x - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(1 + -x - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(1 +-x - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(1+- x - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(1+-x - 1)" ,T(1.0),T(0.0),T(-1)),
test_xy<T>("(1 +- -x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 + +x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("(1 ++x - 1)" ,T(1.0),T(0.0),T(1)),
test_xy<T>("x * 1 == x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("1 * x == x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y * 1 == y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("1 * y == y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * 0 == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("0 * x == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y * 0 == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("0 * y == 0" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + 1 == 1 + x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y + 1 == 1 + y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + y == y + x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * y == y * x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x < y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x <= y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("y >= x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + y > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x + y > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * y > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("x * y > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x + y) > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x + y) > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x * y) > y" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(x * y) > x" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("(2x + 3y) == (2*x + 3*y)" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>("2(x + y) == (2*x + 2*y)" ,T(2.0),T(3.0),T(1.0)),
test_xy<T>(" (x + y)3 == (3*x + 3*y)" ,T(2.0),T(3.0),T(1.0)),
@ -1646,14 +1810,14 @@ inline bool run_test01()
}
}
T result = expression.value();
const T result = expression.value();
if (not_equal(result,test.result))
{
printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n",
test.expr.c_str(),
(double)test.result,
(double)result);
static_cast<double>(test.result),
static_cast<double>(result));
loop_result = false;
}
@ -1758,14 +1922,14 @@ inline bool run_test01()
}
}
T result = expression.value();
const T result = expression.value();
if (not_equal(result,test.result))
{
printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n",
test.expr.c_str(),
(double)test.result,
(double)result);
static_cast<double>(test.result),
static_cast<double>(result));
loop_result = false;
}
@ -1841,14 +2005,14 @@ inline bool run_test01()
}
}
T result = expression.value();
const T result = expression.value();
if (not_equal(result,T(1)))
{
printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n",
expr_list[i].c_str(),
(double)1.0,
(double)result);
static_cast<double>(1.0),
static_cast<double>(result));
loop_result = false;
}
@ -1901,14 +2065,14 @@ inline bool run_test01()
}
}
T result = expression.value();
const T result = expression.value();
if (not_equal(result,T(1)))
{
printf("run_test01() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\n",
expr_list[i].c_str(),
(double)1.0,
(double)result);
static_cast<double>(1.0),
static_cast<double>(result));
loop_result = false;
}
}
@ -2422,6 +2586,17 @@ inline bool run_test02()
test_ab<T>("var i := 0; a[0:i+3] <=> b[:]; (a == '0123X') and (b == 'XXXX4567890')", "XXXXX","01234567890",T(1.0)),
test_ab<T>("var i := 0; a[0:i+4] <=> b[:]; (a == '01234') and (b == 'XXXXX567890')", "XXXXX","01234567890",T(1.0)),
test_ab<T>("var y:= 2; '01234567890'[y:] == a ", "234567890","" ,T(1.0)),
test_ab<T>("var y:= 2; '01234567890'[y:][y:] == a ", "4567890" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '01234567890'[y:][y:][y:] == a ", "67890" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '01234567890'[y:][y:][y:][y:] == a ", "890" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '01234567890'[y:][y:][y:][y:][y:] == a", "0" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '0123456789'[y:] == a ", "23456789" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '0123456789'[y:][y:] == a ", "456789" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '0123456789'[y:][y:][y:] == a ", "6789" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '0123456789'[y:][y:][y:][y:] == a ", "89" ,"" ,T(1.0)),
test_ab<T>("var y:= 2; '0123456789'[y:][y:][y:][y:][y:] == a ", "" ,"" ,T(1.0)),
test_ab<T>("var x := 'XXXXX'; var y := '01234567890'; x[0:0] := y[:]; x == '0XXXX'", "","",T(1.0)),
test_ab<T>("var x := 'XXXXX'; var y := '01234567890'; x[0:1] := y[:]; x == '01XXX'", "","",T(1.0)),
test_ab<T>("var x := 'XXXXX'; var y := '01234567890'; x[0:2] := y[:]; x == '012XX'", "","",T(1.0)),
@ -2598,8 +2773,8 @@ inline bool run_test02()
printf("run_test02() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f\t"
"a='%s'\tb='%s'\tc='%s'\n",
test.expr.c_str(),
(double)test.result,
(double)expr_result,
static_cast<double>(test.result),
static_cast<double>(expr_result),
str_a.c_str(),
str_b.c_str(),
str_c.c_str());
@ -3013,10 +3188,10 @@ inline bool run_test04()
{
printf("run_test04() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\n",
expression_string.c_str(),
(double)result1,
(double)result2,
(double)x,
(double)y);
static_cast<double>(result1),
static_cast<double>(result2),
static_cast<double>(x),
static_cast<double>(y));
return false;
}
@ -3083,10 +3258,10 @@ inline bool run_test05()
{
printf("run_test05() - Computation Error: Expression: [%s]\tExpected: %19.15f\tResult: %19.15f x:%19.15f\ty:%19.15f\tIndex:%d\n",
expression_string.c_str(),
(double)real_result,
(double)result,
(double)x,
(double)y,
static_cast<double>(real_result),
static_cast<double>(result),
static_cast<double>(x),
static_cast<double>(y),
static_cast<unsigned int>(i));
return false;
@ -3140,8 +3315,8 @@ inline bool run_test06()
if (not_equal(total_area1,T(pi) / T(2),T(0.000001)))
{
printf("run_test06() - Integration Error: Expected: %19.15f\tResult: %19.15f\n",
(double)(pi / T(2)),
(double)total_area1);
static_cast<double>(pi / T(2)),
static_cast<double>(total_area1));
return false;
}
@ -3192,9 +3367,9 @@ inline bool run_test07()
if (not_equal(deriv1_result1,deriv1_real_result,T(0.00001)))
{
printf("run_test07() - 1st Derivative Error: x: %19.15f\tExpected: %19.15f\tResult: %19.15f\n",
(double)x,
(double)deriv1_real_result,
(double)deriv1_result1);
static_cast<double>(x),
static_cast<double>(deriv1_real_result),
static_cast<double>(deriv1_result1));
return false;
}
@ -3214,9 +3389,9 @@ inline bool run_test07()
if (not_equal(deriv2_result1,deriv2_real_result,T(0.01)))
{
printf("run_test07() - 2nd Derivative Error: x: %19.15f\tExpected: %19.15f\tResult: %19.15f\n",
(double)x,
(double)deriv2_real_result,
(double)deriv2_result1);
static_cast<double>(x),
static_cast<double>(deriv2_real_result),
static_cast<double>(deriv2_result1));
return false;
}
@ -3236,9 +3411,9 @@ inline bool run_test07()
if (not_equal(deriv3_result1,deriv3_real_result,T(0.01)))
{
printf("run_test07() - 3rd Derivative Error: x: %19.15f\tExpected: %19.15f\tResult: %19.15f\n",
(double)x,
(double)deriv3_real_result,
(double)deriv3_result1);
static_cast<double>(x),
static_cast<double>(deriv3_real_result),
static_cast<double>(deriv3_result1));
return false;
}
@ -3526,9 +3701,9 @@ inline bool run_test09()
const T pi = T(3.141592653589793238462643383279502);
T result = expression.value();
const T result = expression.value();
T expected = T(4) *
const T expected = T(4) *
(
mf(sin(x*pi),y / T(2)) +
mf(sin(x*pi),y / T(2)) +
@ -3545,8 +3720,8 @@ inline bool run_test09()
if (not_equal(result,expected,T(0.0000001)))
{
printf("run_test09() - Error Expected: %19.15f\tResult: %19.15f\n",
(double)expected,
(double)result);
static_cast<double>(expected),
static_cast<double>(result));
return false;
}
@ -4311,6 +4486,78 @@ inline bool run_test10()
{
"var x; 1",
"var x := 1; x",
"var x:= 1; x - -1 == 2",
"var x:= 1; x --1 == 2",
"var x:= 1; x-- 1 == 2",
"var x:= 1; x--1 == 2",
"var x:= 1; x -- -1== 0",
"var x:= 1; x + -1 == 0",
"var x:= 1; x +-1 == 0",
"var x:= 1; x+- 1 == 0",
"var x:= 1; x+-1 == 0",
"var x:= 1; x +- -1== 2",
"var x:= 1; x + +1 == 2",
"var x:= 1; x ++1 == 2",
"var x:= 1; 1 - -x == 2",
"var x:= 1; 1 --x == 2",
"var x:= 1; 1-- x == 2",
"var x:= 1; 1--x == 2",
"var x:= 1; 1 -- -x== 0",
"var x:= 1; 1 + -x == 0",
"var x:= 1; 1 +-x == 0",
"var x:= 1; 1+- x == 0",
"var x:= 1; 1+-x == 0",
"var x:= 1; 1 +- -x== 2",
"var x:= 1; 1 + +x == 2",
"var x:= 1; 1 ++x == 2",
"var x:= 1; (x - -1 + 1) == 3",
"var x:= 1; (x --1 + 1) == 3",
"var x:= 1; (x-- 1 + 1) == 3",
"var x:= 1; (x--1 + 1) == 3",
"var x:= 1; (x -- -1 + 1) == 1",
"var x:= 1; (x + -1 + 1) == 1",
"var x:= 1; (x +-1 + 1) == 1",
"var x:= 1; (x+- 1 + 1) == 1",
"var x:= 1; (x+-1 + 1) == 1",
"var x:= 1; (x +- -1 + 1) == 3",
"var x:= 1; (x + +1 + 1) == 3",
"var x:= 1; (x ++1 + 1) == 3",
"var x:= 1; (1 - -x + 1) == 3",
"var x:= 1; (1 --x + 1) == 3",
"var x:= 1; (1-- x + 1) == 3",
"var x:= 1; (1--x + 1) == 3",
"var x:= 1; (1 -- -x + 1) == 1",
"var x:= 1; (1 + -x + 1) == 1",
"var x:= 1; (1 +-x + 1) == 1",
"var x:= 1; (1+- x + 1) == 1",
"var x:= 1; (1+-x + 1) == 1",
"var x:= 1; (1 +- -x + 1) == 3",
"var x:= 1; (1 + +x + 1) == 3",
"var x:= 1; (1 ++x + 1) == 3",
"var x:= 1; (x - -1 - 1) == 1",
"var x:= 1; (x --1 - 1) == 1",
"var x:= 1; (x-- 1 - 1) == 1",
"var x:= 1; (x--1 - 1) == 1",
"var x:= 1; (x -- -1 - 1) == -1",
"var x:= 1; (x + -1 - 1) == -1",
"var x:= 1; (x +-1 - 1) == -1",
"var x:= 1; (x+- 1 - 1) == -1",
"var x:= 1; (x+-1 - 1) == -1",
"var x:= 1; (x +- -1 - 1) == 1",
"var x:= 1; (x + +1 - 1) == 1",
"var x:= 1; (x ++1 - 1) == 1",
"var x:= 1; (1 - -x - 1) == 1",
"var x:= 1; (1 --x - 1) == 1",
"var x:= 1; (1-- x - 1) == 1",
"var x:= 1; (1--x - 1) == 1",
"var x:= 1; (1 -- -x - 1) == -1",
"var x:= 1; (1 + -x - 1) == -1",
"var x:= 1; (1 +-x - 1) == -1",
"var x:= 1; (1+- x - 1) == -1",
"var x:= 1; (1+-x - 1) == -1",
"var x:= 1; (1 +- -x - 1) == 1",
"var x:= 1; (1 + +x - 1) == 1",
"var x:= 1; (1 ++x - 1) == 1",
"var x := 1; var y := 2; 1",
"var x := 1; var y := 2; x",
"var x:=6; var y:=4; x + -3 == 3",
@ -4662,7 +4909,7 @@ inline bool run_test10()
}
}
T result = expression.value();
const T result = expression.value();
if (T(1) != result)
{
@ -4699,7 +4946,7 @@ inline bool run_test10()
continue;
}
T result = expression.value();
const T result = expression.value();
if (T(1) != result)
{
@ -5287,8 +5534,8 @@ inline bool run_test15()
if (not_equal(base_result,result))
{
printf("run_test15() - Error in evaluation! (1) Base: %20.10f\tResult: %20.10f\tExpression: %s\n",
(double)base_result,
(double)result,
static_cast<double>(base_result),
static_cast<double>(result),
expr_str_list[i].c_str());
failure = true;
@ -5917,6 +6164,96 @@ struct overload_func : exprtk::igeneric_function<T>
template <typename T>
inline bool run_test18()
{
{
exprtk::symbol_table<T> symbol_table;
symbol_table.remove_variable("x",true);
symbol_table.remove_variable("x",false);
symbol_table.remove_stringvar("x");
symbol_table.remove_function("x");
symbol_table.remove_vararg_function("x");
symbol_table.remove_vector("x");
}
{
exprtk::symbol_table<T> symbol_table;
{
T x;
const bool result1 = symbol_table.add_variable("x", x);
const bool result2 = symbol_table.remove_variable("x");
const bool result3 = symbol_table.remove_variable("x");
if (!result1 || !result2 || result3)
{
printf("run_test18() - Failed sym_tab add/remove [1]\n");
}
}
{
std::string x;
const bool result1 = symbol_table.add_stringvar("x", x);
const bool result2 = symbol_table.remove_stringvar("x");
const bool result3 = symbol_table.remove_stringvar("x");
if (!result1 || !result2 || result3)
{
printf("run_test18() - Failed sym_tab add/remove [2]\n");
}
}
{
std::vector<T> x(10,T(0));
const bool result1 = symbol_table.add_vector("x", x);
const bool result2 = symbol_table.remove_vector("x");
const bool result3 = symbol_table.remove_vector("x");
if (!result1 || !result2 || result3)
{
printf("run_test18() - Failed sym_tab add/remove [3]\n");
}
}
{
myfunc<T> x;
const bool result1 = symbol_table.add_function("x", x);
const bool result2 = symbol_table.remove_function("x");
const bool result3 = symbol_table.remove_function("x");
if (!result1 || !result2 || result3)
{
printf("run_test18() - Failed sym_tab add/remove [4]\n");
}
}
{
va_func<T> x;
const bool result1 = symbol_table.add_function("x", x);
const bool result2 = symbol_table.remove_vararg_function("x");
const bool result3 = symbol_table.remove_vararg_function("x");
if (!result1 || !result2 || result3)
{
printf("run_test18() - Failed sym_tab add/remove [5]\n");
}
}
{
symbol_table.add_function("foo1",foo1);
symbol_table.add_function("foo2",foo2);
symbol_table.add_function("foo3",foo3);
symbol_table.add_function("foo4",foo4);
symbol_table.add_function("foo5",foo5);
symbol_table.add_function("foo6",foo6);
symbol_table.remove_function("foo1");
symbol_table.remove_function("foo2");
symbol_table.remove_function("foo3");
symbol_table.remove_function("foo4");
symbol_table.remove_function("foo5");
symbol_table.remove_function("foo6");
}
}
{
typedef exprtk::expression<T> expression_t;
@ -6448,7 +6785,7 @@ inline bool run_test18()
return false;
}
T result = expression.value();
const T result = expression.value();
if (result != T(1))
{
@ -7041,7 +7378,7 @@ inline bool run_test18()
continue;
}
T result = expression.value();
const T result = expression.value();
if (result != T(1))
{
@ -7564,7 +7901,7 @@ inline bool run_test19()
continue;
}
T result = expression.value();
const T result = expression.value();
if (result_list[i] != result)
{
@ -8061,15 +8398,15 @@ inline bool run_test19()
{
x = static_cast<T>(i);
T result = expression.value();
const T result = expression.value();
if (not_equal(result,std::sqrt(x),T(0.0000001)))
{
printf("run_test19() - Computation Error "
"Expression: [%s]\tExpected: %12.8f\tResult: %12.8f\n",
expression_str.c_str(),
(double)std::sqrt(x),
(double)result);
static_cast<double>(std::sqrt(x)),
static_cast<double>(result));
failure = true;
}
@ -8191,7 +8528,7 @@ inline bool run_test19()
sum += x;
T result = expression.value();
const T result = expression.value();
if (result != sum)
{