C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
03c90e1893
commit
f6a56d8048
580
exprtk.hpp
580
exprtk.hpp
File diff suppressed because it is too large
Load Diff
131
exprtk_test.cpp
131
exprtk_test.cpp
|
@ -1028,7 +1028,31 @@ static const test_t test_list[] =
|
|||
test_t("((1 + 1) < 3 ? 7 : 9) == 7",1.0),
|
||||
test_t("((1 + 1) < (3 + 3) ? 7 : 9) == 7",1.0),
|
||||
test_t("(min(1,2) ? 1 + 3 : 1 + 4) == 4",1.0),
|
||||
test_t("(min(0,1) ? 1 + 3 : 1 + 4) == 5",1.0)
|
||||
test_t("(min(0,1) ? 1 + 3 : 1 + 4) == 5",1.0),
|
||||
test_t("if(1 < 2) 3; == 3",1.0),
|
||||
test_t("if(1 > 2) 3; == null",1.0),
|
||||
test_t("if(1 < 2) 3; else 4; == 3",1.0),
|
||||
test_t("if(1 > 2) 3; else 4; == 4",1.0),
|
||||
test_t("if(1 < 2) 3; else {1+2; 4;} == 3",1.0),
|
||||
test_t("if(1 > 2) 3; else {1+2; 4;} == 4",1.0),
|
||||
test_t("if(1 < 2) 3; else if (1 < 2) 4; == 3",1.0),
|
||||
test_t("if(1 > 2) 3; else if (1 < 2) 4; == 4",1.0),
|
||||
test_t("if(1 > 2) 3; else if (1 > 2) 4; == null",1.0),
|
||||
test_t("if(1 < 2) 3; else if (1 < 2) {1+2; 4;} == 3",1.0),
|
||||
test_t("if(1 > 2) 3; else if (1 < 2) {1+2; 4;} == 4",1.0),
|
||||
test_t("if(1 > 2) 3; else if (1 > 2) {1+2; 4;} == null",1.0),
|
||||
test_t("if(1 < 2) { 1+2; 3;} == 3",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} == null",1.0),
|
||||
test_t("if(1 < 2) { 1+2; 3;} else 4; == 3",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} else 4; == 4",1.0),
|
||||
test_t("if(1 < 2) { 1+2; 3;} else {1+2; 4;} == 3",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} else {1+2; 4;} == 4",1.0),
|
||||
test_t("if(1 < 2) { 1+2; 3;} else if (1 < 2) 4; == 3",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} else if (1 < 2) 4; == 4",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} else if (1 > 2) 4; == null",1.0),
|
||||
test_t("if(1 < 2) { 1+2; 3;} else if (1 < 2) {1+2; 4;} == 3",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} else if (1 < 2) {1+2; 4;} == 4",1.0),
|
||||
test_t("if(1 > 2) { 1+2; 3;} else if (1 > 2) {1+2; 4;} == null",1.0)
|
||||
};
|
||||
|
||||
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_t);
|
||||
|
@ -1164,13 +1188,14 @@ struct test_xy
|
|||
};
|
||||
|
||||
template <typename T>
|
||||
struct test_xyz
|
||||
struct test_xyzw
|
||||
{
|
||||
test_xyz(std::string e, const T& v0, const T& v1, const T& v2, const T& r)
|
||||
test_xyzw(std::string e, const T& v0, const T& v1, const T& v2, const T& v3, const T& r)
|
||||
: expr(e),
|
||||
x(v0),
|
||||
y(v1),
|
||||
z(v2),
|
||||
w(v3),
|
||||
result(r)
|
||||
{}
|
||||
|
||||
|
@ -1178,6 +1203,7 @@ struct test_xyz
|
|||
T x;
|
||||
T y;
|
||||
T z;
|
||||
T w;
|
||||
T result;
|
||||
};
|
||||
|
||||
|
@ -1537,51 +1563,63 @@ inline bool run_test01()
|
|||
}
|
||||
|
||||
{
|
||||
static const test_xyz<T> test_list[] =
|
||||
static const test_xyzw<T> test_list[] =
|
||||
{
|
||||
test_xyz<T>("((x / y) / z )",T(7.0),T(9.0),T(3.0),T(((7.0 / 9.0) / 3.0 ))),
|
||||
test_xyz<T>("((x / y) / 2 )",T(7.0),T(9.0),T(3.0),T(((7.0 / 9.0) / 2.0 ))),
|
||||
test_xyz<T>("((x / 2) / y )",T(7.0),T(9.0),T(3.0),T(((7.0 / 2.0) / 9.0 ))),
|
||||
test_xyz<T>("((2 / x) / y )",T(7.0),T(9.0),T(3.0),T(((2.0 / 7.0) / 9.0 ))),
|
||||
test_xyz<T>("( x / (y / z))",T(7.0),T(9.0),T(3.0),T(( 7.0 / (9.0 / 3.0)))),
|
||||
test_xyz<T>("( x / (y / 2))",T(7.0),T(9.0),T(3.0),T(( 7.0 / (9.0 / 2.0)))),
|
||||
test_xyz<T>("( x / (2 / y))",T(7.0),T(9.0),T(3.0),T(( 7.0 / (2.0 / 9.0)))),
|
||||
test_xyz<T>("( 2 / (x / y))",T(7.0),T(9.0),T(3.0),T(( 2.0 / (7.0 / 9.0)))),
|
||||
test_xyz<T>("([(min(x,y) + z) + 3] - 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) - 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) + 3] + 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) + 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) + 3] * 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) * 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) + 3] / 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) / 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) - 3] - 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) - 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) - 3] + 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) + 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) - 3] * 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) * 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) - 3] / 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) / 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) * 3] - 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) - 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) * 3] + 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) + 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) * 3] * 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) * 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) * 3] / 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) / 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) / 3] - 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) - 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) / 3] + 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) + 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) / 3] * 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) * 4.0))),
|
||||
test_xyz<T>("([(min(x,y) + z) / 3] / 4)",T(5.0),T(7.0),T(9.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) / 4.0))),
|
||||
test_xyz<T>("(4 - [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 - (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 + [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 + (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 * [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 * (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 / [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 / (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 - [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 - (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 + [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 + (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 * [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 * (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 / [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 / (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 - [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 - (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 + [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 + (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 * [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 * (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 / [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 / (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 - [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 - (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 + [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 + (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 * [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 * (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyz<T>("(4 / [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T((4.0 / (3.0 / (std::min(5.0,7.0) + 9.0)))))
|
||||
test_xyzw<T>("((x / y) / z )",T(7.0),T(9.0),T(3.0),T(0.0),T(((7.0 / 9.0) / 3.0 ))),
|
||||
test_xyzw<T>("((x / y) / 2 )",T(7.0),T(9.0),T(3.0),T(0.0),T(((7.0 / 9.0) / 2.0 ))),
|
||||
test_xyzw<T>("((x / 2) / y )",T(7.0),T(9.0),T(3.0),T(0.0),T(((7.0 / 2.0) / 9.0 ))),
|
||||
test_xyzw<T>("((2 / x) / y )",T(7.0),T(9.0),T(3.0),T(0.0),T(((2.0 / 7.0) / 9.0 ))),
|
||||
test_xyzw<T>("( x / (y / z))",T(7.0),T(9.0),T(3.0),T(0.0),T(( 7.0 / (9.0 / 3.0)))),
|
||||
test_xyzw<T>("( x / (y / 2))",T(7.0),T(9.0),T(3.0),T(0.0),T(( 7.0 / (9.0 / 2.0)))),
|
||||
test_xyzw<T>("( x / (2 / y))",T(7.0),T(9.0),T(3.0),T(0.0),T(( 7.0 / (2.0 / 9.0)))),
|
||||
test_xyzw<T>("( 2 / (x / y))",T(7.0),T(9.0),T(3.0),T(0.0),T(( 2.0 / (7.0 / 9.0)))),
|
||||
test_xyzw<T>("([(min(x,y) + z) + 3] - 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) - 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) + 3] + 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) + 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) + 3] * 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) * 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) + 3] / 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) + 3.0) / 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) - 3] - 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) - 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) - 3] + 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) + 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) - 3] * 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) * 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) - 3] / 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) - 3.0) / 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) * 3] - 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) - 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) * 3] + 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) + 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) * 3] * 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) * 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) * 3] / 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) * 3.0) / 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) / 3] - 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) - 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) / 3] + 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) + 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) / 3] * 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) * 4.0))),
|
||||
test_xyzw<T>("([(min(x,y) + z) / 3] / 4)",T(5.0),T(7.0),T(9.0),T(0.0),T((((std::min(5.0,7.0) + 9.0) / 3.0) / 4.0))),
|
||||
test_xyzw<T>("(4 - [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 - (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 + [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 + (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 * [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 * (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 / [3 + (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 / (3.0 + (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 - [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 - (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 + [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 + (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 * [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 * (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 / [3 - (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 / (3.0 - (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 - [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 - (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 + [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 + (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 * [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 * (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 / [3 * (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 / (3.0 * (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 - [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 - (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 + [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 + (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 * [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 * (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("(4 / [3 / (min(x,y) + z)])",T(5.0),T(7.0),T(9.0),T(0.0),T((4.0 / (3.0 / (std::min(5.0,7.0) + 9.0))))),
|
||||
test_xyzw<T>("if(x < y) { z+2; z;} == z" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} == null" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x < y) { z+2; z;} else w; == z" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} else 1 + w; == (w + 1)" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x < y) { z+2; z;} else {1+2; w;} == z" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} else {1+2; w;} == w" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x < y) { z+2; z;} else if (x < y) w; == z" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} else if (x < y) 1 + w; == w + 1" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} else if (x > y) w; == null" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x < y) { z+2; z;} else if (x < y) {w+2; w;} == z" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} else if (x < y) {w+2; w;} == w" ,T(1.0),T(2.0),T(3.0),T(4.0),T(1.0)),
|
||||
test_xyzw<T>("if(x > y) { z+2; z;} else if (x > y) {w+2; w;} == null",T(1.0),T(2.0),T(3.0),T(4.0),T(1.0))
|
||||
};
|
||||
|
||||
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_xyz<T>);
|
||||
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_xyzw<T>);
|
||||
|
||||
const std::size_t rounds = 60;
|
||||
|
||||
|
@ -1590,12 +1628,13 @@ inline bool run_test01()
|
|||
bool loop_result = true;
|
||||
for (std::size_t i = 0; i < test_list_size; ++i)
|
||||
{
|
||||
test_xyz<T>& test = const_cast<test_xyz<T>&>(test_list[i]);
|
||||
test_xyzw<T>& test = const_cast<test_xyzw<T>&>(test_list[i]);
|
||||
|
||||
exprtk::symbol_table<T> symbol_table;
|
||||
symbol_table.add_variable("x",test.x);
|
||||
symbol_table.add_variable("y",test.y);
|
||||
symbol_table.add_variable("z",test.z);
|
||||
symbol_table.add_variable("w",test.w);
|
||||
|
||||
exprtk::expression<T> expression;
|
||||
expression.register_symbol_table(symbol_table);
|
||||
|
|
64
readme.txt
64
readme.txt
|
@ -83,7 +83,7 @@ http://www.opensource.org/licenses/cpl1.0.php
|
|||
|
||||
|
||||
[04 - DOWNLOADS & UPDATES]
|
||||
The most recent version of the C++ Mathematical Expression Toolkit
|
||||
The most recent version of the C++ Mathematical Expression Toolkit
|
||||
Library including all updates and tests can be found at the following
|
||||
locations:
|
||||
|
||||
|
@ -93,7 +93,7 @@ locations:
|
|||
|
||||
|
||||
[05 - INSTALLATION]
|
||||
The header file exprtk.hpp should be placed in a project or system
|
||||
The header file exprtk.hpp should be placed in a project or system
|
||||
include path (e.g: /usr/include/).
|
||||
|
||||
|
||||
|
@ -174,7 +174,7 @@ include path (e.g: /usr/include/).
|
|||
+----------+---------------------------------------------------------+
|
||||
| mor | Multi-input logical OR, True if at least one of the |
|
||||
| | inputs are true. Left to right short-circuiting of |
|
||||
| | expressions. (eg: mor(x > y, z < w, u or v, w and x)) |
|
||||
| | expressions. (eg: mor(x > y, z < w, u or v, w and x)) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| nand | Logical NAND, True only if either x or y is false. |
|
||||
| | (eg: x nand y) |
|
||||
|
@ -188,16 +188,16 @@ include path (e.g: /usr/include/).
|
|||
| 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 |
|
||||
| | differ. (eg: x xor y) |
|
||||
| | differ. (eg: x xor y) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| 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 |
|
||||
| | 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 |
|
||||
| | circuiting optimisation. (eg: (x | y) == (y or x)) |
|
||||
| | circuiting optimisation. (eg: (x | y) == (y or x)) |
|
||||
+----------+---------------------------------------------------------+
|
||||
|
||||
(3) General Purpose Functions
|
||||
|
@ -296,7 +296,7 @@ include path (e.g: /usr/include/).
|
|||
| atan | Arc tangent of x expressed in radians. Interval [-1,+1] |
|
||||
| | (eg: atan(x)) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| atan2 | Arc tangent of (x/y) expressed in radians. [-pi,+pi] |
|
||||
| atan2 | Arc tangent of (x / y) expressed in radians. [-pi,+pi] |
|
||||
| | eg: atan2(x,y) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| atanh | Inverse hyperbolic tangent of x expressed in radians. |
|
||||
|
@ -354,11 +354,11 @@ include path (e.g: /usr/include/).
|
|||
+----------+---------------------------------------------------------+
|
||||
| [r0:r1] | The closed interval [r0,r1] of the specified string. |
|
||||
| | eg: Given a string x with a value of 'abcdefgh' then: |
|
||||
| | 0. x[1:4] == 'bcde' |
|
||||
| | 1. x[ :5] == x[:5] == 'abcdef' |
|
||||
| | 2. x[3: ] == x[3:] =='cdefgh' |
|
||||
| | 3. x[ : ] == x[:] == 'abcdefgh' |
|
||||
| | 4. x[4/2:3+2] == x[2:5] == 'cdef' |
|
||||
| | 1. x[1:4] == 'bcde' |
|
||||
| | 2. x[ :5] == x[:5] == 'abcdef' |
|
||||
| | 3. x[3: ] == x[3:] =='cdefgh' |
|
||||
| | 4. x[ : ] == x[:] == 'abcdefgh' |
|
||||
| | 5. x[4/2:3+2] == x[2:5] == 'cdef' |
|
||||
| | |
|
||||
| | Note: Both r0 and r1 are assumed to be integers, where |
|
||||
| | r0 <= r1. They may also be the result of an expression, |
|
||||
|
@ -371,7 +371,27 @@ include path (e.g: /usr/include/).
|
|||
|STRUCTURE | DEFINITION |
|
||||
+----------+---------------------------------------------------------+
|
||||
| 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: |
|
||||
| | 1. if(x, y, z) |
|
||||
| | 2. if((x + 1) > 2y, z + 1, w / v) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| if-else | The if-else/else-if statement. Subject to the condition |
|
||||
| | branch the statement will return either the value of the|
|
||||
| | consequent or the alternative branch. |
|
||||
| | eg: |
|
||||
| | 1. if (x > y) z; else w; |
|
||||
| | 2. if (x > y) z; else if (w != u) v; |
|
||||
| | 3. if (x < y) {z; w+1;} else u; |
|
||||
| | 4. if ((x != y) and (z > w)) |
|
||||
| | { |
|
||||
| | y := sin(x) / u; |
|
||||
| | z := w+1; |
|
||||
| | } |
|
||||
| | else if (x > (z + 1)) |
|
||||
| | { |
|
||||
| | w := abs (x - y) + z; |
|
||||
| | u := (x + 1) > 2y ? 2u : 3u; |
|
||||
| | } |
|
||||
+----------+---------------------------------------------------------+
|
||||
| switch | The first true case condition that is encountered will |
|
||||
| | determine the result of the switch. If none of the case |
|
||||
|
@ -410,9 +430,9 @@ include path (e.g: /usr/include/).
|
|||
| ?: | Ternary conditional statement, similar to that of the |
|
||||
| | above denoted if-statement. |
|
||||
| | eg: |
|
||||
| | 0. x ? y : z |
|
||||
| | 1. x + 1 > 2y ? z + 1 : (w / v) |
|
||||
| | 2. min(x,y) > z ? (x < y + 1) ? x : y : (w * v) |
|
||||
| | 1. x ? y : z |
|
||||
| | 2. x + 1 > 2y ? z + 1 : (w / v) |
|
||||
| | 3. min(x,y) > z ? (x < y + 1) ? x : y : (w * v) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| ~ | Evaluate each sub-expression, then return as the result |
|
||||
| | the value of the last sub-expression. This is sometimes |
|
||||
|
@ -433,8 +453,8 @@ include path (e.g: /usr/include/).
|
|||
| | } |
|
||||
+----------+---------------------------------------------------------+
|
||||
|
||||
Note: In the above tables, the symbols x, y, z and w where appropriate
|
||||
can represent any of one the following:
|
||||
Note: In the above tables, the symbols x, y, z, w, u and v where
|
||||
appropriate may represent any of one the following:
|
||||
|
||||
1. Literal numeric/string value
|
||||
2. A variable
|
||||
|
@ -447,9 +467,9 @@ There are three primary components, that are specialized upon a given
|
|||
numeric type, which make up the core of ExprTk. The components are as
|
||||
follows:
|
||||
|
||||
1. Symbol Table exprtk::symbol_table<NumericType>
|
||||
2. Expression exprtk::expression<NumericType>
|
||||
3. Parser exprtk::parser<NumericType>
|
||||
1. Symbol Table exprtk::symbol_table<NumericType>
|
||||
2. Expression exprtk::expression<NumericType>
|
||||
3. Parser exprtk::parser<NumericType>
|
||||
|
||||
|
||||
(1) Symbol Table
|
||||
|
|
Loading…
Reference in New Issue