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

This commit is contained in:
Arash Partow 2015-04-22 20:54:34 +10:00
parent 6862a5a1dc
commit 1f1adca8ac
3 changed files with 446 additions and 420 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1035,30 +1035,30 @@ static const test_t test_list[] =
test_t("((1 + 1) < (3 + 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(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; == 3",1.0),
test_t("if(1 > 2) 3; == null",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; == 3",1.0),
test_t("if(1 > 2) 3; else 4; == 4",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;} == 3",1.0),
test_t("if(1 > 2) 3; else {1+2; 4;} == 4",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; == 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; == 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) 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;} == 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;} == 4",1.0),
test_t("if(1 > 2) 3; else if (1 > 2) {1+2; 4;} == null",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;} == 3",1.0),
test_t("if(1 > 2) { 1+2; 3;} == null",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; == 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 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;} == 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 {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; == 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; == 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) 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;} == 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;} == 4",1.0),
test_t("if(1 > 2) { 1+2; 3;} else if (1 > 2) {1+2; 4;} == null",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); static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_t);
@ -1679,18 +1679,18 @@ inline bool run_test01()
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;} == 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;} == 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 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 + 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;} == 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 {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) 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) 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; == 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;} == 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;} == 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)) 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_xyzw<T>); static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_xyzw<T>);
@ -5917,16 +5917,16 @@ inline bool run_test19()
compositor compositor
.add("is_prime_impl1", .add("is_prime_impl1",
"if(y == 1,true, " "if (y == 1,true, "
" if(0 == (x % y),false, " " if (0 == (x % y),false, "
" is_prime_impl1(x,y - 1)))", " is_prime_impl1(x,y - 1))) ",
"x","y"); "x","y");
compositor compositor
.add("is_prime1", .add("is_prime1",
"if(frac(x) != 0, false, " "if (frac(x) != 0, false, "
" if(x <= 0, false, " " if (x <= 0, false, "
" is_prime_impl1(x,min(x - 1,trunc(sqrt(x)) + 1))))", " is_prime_impl1(x,min(x - 1,trunc(sqrt(x)) + 1)))) ",
"x"); "x");
compositor compositor
@ -6122,9 +6122,9 @@ inline bool run_test19()
compositor compositor
.add("fibonacci1", .add("fibonacci1",
"if(x == 0,0, " "if (x == 0,0, "
" if(x == 1,1, " " if (x == 1,1, "
" fibonacci1(x - 1) + fibonacci1(x - 2)))", " fibonacci1(x - 1) + fibonacci1(x - 2)))",
"x"); "x");
compositor compositor
@ -6139,19 +6139,19 @@ inline bool run_test19()
compositor compositor
.add("fibonacci_impl3", .add("fibonacci_impl3",
"switch " "switch "
"{ " "{ "
" case x == 0 : 0; " " case x == 0 : 0; "
" case x == 1 : 1; " " case x == 1 : 1; "
" default : " " default : "
" while ((x := (x - 1)) > 0)" " while ((x := (x - 1)) > 0) "
" { " " { "
" w := z; " " w := z; "
" z := z + y; " " z := z + y; "
" y := w; " " y := w; "
" z " " z "
" }; " " }; "
"} ", "} ",
"x","y","z","w"); "x","y","z","w");
compositor compositor
@ -6161,19 +6161,19 @@ inline bool run_test19()
compositor compositor
.add("fibonacci_impl4", .add("fibonacci_impl4",
"switch " "switch "
"{ " "{ "
" case x == 0 : 0; " " case x == 0 : 0; "
" case x == 1 : 1; " " case x == 1 : 1; "
" default : " " default : "
" repeat " " repeat "
" w := z; " " w := z; "
" z := z + y; " " z := z + y; "
" y := w; " " y := w; "
" x := x - 1; " " x := x - 1; "
" z " " z "
" until (x <= 1);" " until (x <= 1); "
"} ", "} ",
"x","y","z","w"); "x","y","z","w");
compositor compositor
@ -6731,21 +6731,21 @@ inline bool run_test21()
static const std::string result_list[] = static const std::string result_list[] =
{ {
"" , "" ,
"T" , "T" ,
"TT" , "TT" ,
"TT" , "TT" ,
"TTS", "TTS" ,
"TS" , "TS" ,
"TST", "TST" ,
"TS" , "TS" ,
"TST", "TST" ,
"T" , "T" ,
"TS" , "TS" ,
"TST", "TST" ,
"TSTT", "TSTT" ,
"TSTTT", "TSTTT",
"TST", "TST" ,
"TS" "TS"
}; };
@ -6793,13 +6793,13 @@ inline bool run_test21()
{ {
static const std::string expression_list[] = static const std::string expression_list[] =
{ {
"x := 1; x + 1; x + 2; x + 3; x + 5; x + 7; return [x + 1];", "x := 1; x + 1; x + 2; x + 3; x + 5; x + 7; return [x + 1]; ",
"x := 1; x + 1; x + 2; x + 3; x + 5; return [x + 1]; x := 7;", "x := 1; x + 1; x + 2; x + 3; x + 5; return [x + 1]; x := 7; ",
"x := 1; x + 1; x + 2; x + 3; return [x + 1]; x + 5; x := 7;", "x := 1; x + 1; x + 2; x + 3; return [x + 1]; x + 5; x := 7; ",
"x := 1; x + 1; x + 2; return [x + 1]; x + 3; x + 5; x := 7;", "x := 1; x + 1; x + 2; return [x + 1]; x + 3; x + 5; x := 7; ",
"x := 1; x + 1; return [x + 1]; x + 2; x + 3; x + 5; x := 7;", "x := 1; x + 1; return [x + 1]; x + 2; x + 3; x + 5; x := 7; ",
"x := 1; return [x + 1]; x + 1; x + 2; x + 3; x + 5; x := 7;", "x := 1; return [x + 1]; x + 1; x + 2; x + 3; x + 5; x := 7; ",
"return [x + 1]; x := 1; x + 1; x + 2; x + 3; x + 5; x := 7;", "return [x + 1]; x := 1; x + 1; x + 2; x + 3; x + 5; x := 7; ",
"~{x := 1; x + 1; x + 2; x + 3; x + 5; x + 7; return [x + 1]}", "~{x := 1; x + 1; x + 2; x + 3; x + 5; x + 7; return [x + 1]}",
"~{x := 1; x + 1; x + 2; x + 3; x + 5; return [x + 1]; x := 7}", "~{x := 1; x + 1; x + 2; x + 3; x + 5; return [x + 1]; x := 7}",
"~{x := 1; x + 1; x + 2; x + 3; return [x + 1]; x + 5; x := 7}", "~{x := 1; x + 1; x + 2; x + 3; return [x + 1]; x + 5; x := 7}",

View File

@ -93,7 +93,7 @@ Library including all updates and tests can be found at the following
locations: locations:
(a) Download: http://www.partow.net/programming/exprtk/index.html (a) Download: http://www.partow.net/programming/exprtk/index.html
(b) Repository: https://exprtk.googlecode.com/svn/ (b) Repository: https://github.com/ArashPartow/exprtk