C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
4aa02953f8
commit
751226b946
6
Makefile
6
Makefile
|
@ -37,6 +37,7 @@ BUILD_LIST+=exprtk_simple_example_10
|
|||
BUILD_LIST+=exprtk_simple_example_11
|
||||
BUILD_LIST+=exprtk_simple_example_12
|
||||
BUILD_LIST+=exprtk_simple_example_13
|
||||
BUILD_LIST+=exprtk_simple_example_14
|
||||
|
||||
all: $(BUILD_LIST)
|
||||
|
||||
|
@ -85,6 +86,9 @@ exprtk_simple_example_12: exprtk_simple_example_12.cpp exprtk.hpp
|
|||
exprtk_simple_example_13: exprtk_simple_example_13.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_13 exprtk_simple_example_13.cpp $(LINKER_OPT)
|
||||
|
||||
exprtk_simple_example_14: exprtk_simple_example_14.cpp exprtk.hpp
|
||||
$(COMPILER) $(OPTIONS) exprtk_simple_example_14 exprtk_simple_example_14.cpp $(LINKER_OPT)
|
||||
|
||||
pgo: exprtk_test.cpp exprtk_benchmark.cpp exprtk.hpp
|
||||
$(COMPILER) $(BASE_OPTIONS) -O3 -march=native -fprofile-generate -o exprtk_benchmark exprtk_benchmark.cpp $(LINKER_OPT)
|
||||
./exprtk_benchmark
|
||||
|
@ -106,6 +110,7 @@ strip_bin:
|
|||
strip -s exprtk_simple_example_11
|
||||
strip -s exprtk_simple_example_12
|
||||
strip -s exprtk_simple_example_13
|
||||
strip -s exprtk_simple_example_14
|
||||
|
||||
valgrind_check:
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_test_valgrind.log -v ./exprtk_test
|
||||
|
@ -123,6 +128,7 @@ valgrind_check:
|
|||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_11_valgrind.log -v ./exprtk_simple_example_11
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_12_valgrind.log -v ./exprtk_simple_example_12
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_13_valgrind.log -v ./exprtk_simple_example_13
|
||||
valgrind --leak-check=full --show-reachable=yes --track-origins=yes --log-file=exprtk_simple_example_14_valgrind.log -v ./exprtk_simple_example_14
|
||||
|
||||
clean:
|
||||
rm -f core.* *~ *.o *.bak *stackdump gmon.out *.gcda *.gcno *.gcnor *.gch
|
||||
|
|
2592
exprtk.hpp
2592
exprtk.hpp
File diff suppressed because it is too large
Load Diff
|
@ -43,17 +43,18 @@ void savitzky_golay_filter()
|
|||
" var lower_bound := trunc(weight[] / 2); "
|
||||
" var upper_bound := v_in[] - lower_bound; "
|
||||
" "
|
||||
" v_out := 0; "
|
||||
" "
|
||||
" for (i := lower_bound; i < upper_bound; i += 1) "
|
||||
" { "
|
||||
" v_out[i] := 0; "
|
||||
" for (j := 0; j < weight[]; j += 1) "
|
||||
" for (j := -lower_bound; j <= lower_bound; j += 1) "
|
||||
" { "
|
||||
" var index := i + j - lower_bound; "
|
||||
" v_out[i] += weight[j] * v_in[index]; "
|
||||
" v_out[i] += weight[j + lower_bound] * v_in[i + j]; "
|
||||
" }; "
|
||||
" v_out[i] /= 231; "
|
||||
" }; "
|
||||
" "
|
||||
" v_out /= sum(weight); "
|
||||
" "
|
||||
" for (i := 0; i < lower_bound; i += 1) "
|
||||
" { "
|
||||
" v_out[i] := 0; "
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
/*
|
||||
**************************************************************
|
||||
* C++ Mathematical Expression Toolkit Library *
|
||||
* *
|
||||
* Simple Example 14 *
|
||||
* Author: Arash Partow (1999-2014) *
|
||||
* URL: http://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 Common Public License. *
|
||||
* http://www.opensource.org/licenses/cpl1.0.php *
|
||||
* *
|
||||
**************************************************************
|
||||
*/
|
||||
|
||||
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
#include <ctime>
|
||||
#include <string>
|
||||
#include "exprtk.hpp"
|
||||
|
||||
|
||||
template<typename T>
|
||||
void stddev_example()
|
||||
{
|
||||
typedef exprtk::symbol_table<T> symbol_table_t;
|
||||
typedef exprtk::expression<T> expression_t;
|
||||
typedef exprtk::parser<T> parser_t;
|
||||
|
||||
std::string stddev_program =
|
||||
" var x[25] := { "
|
||||
" 1, 2, 3, 4, 5, "
|
||||
" 6, 7, 8, 9, 10, "
|
||||
" 11, 12, 13, 14, 15, "
|
||||
" 16, 17, 18, 19, 20, "
|
||||
" 21, 22, 23, 24, 25 "
|
||||
" }; "
|
||||
" "
|
||||
" sqrt(sum([x - avg(x)]^2) / x[]) ";
|
||||
|
||||
expression_t expression;
|
||||
|
||||
parser_t parser;
|
||||
|
||||
parser.compile(stddev_program,expression);
|
||||
|
||||
T stddev = expression.value();
|
||||
|
||||
printf("stddev(1..25) = %10.6f\n",stddev);
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
stddev_example<double>();
|
||||
return 0;
|
||||
}
|
137
exprtk_test.cpp
137
exprtk_test.cpp
|
@ -2026,7 +2026,16 @@ inline bool run_test02()
|
|||
test_ab<T>("('!@#$%^&*([{}])-=') == ('!@#$%^&*([{}])-=')","","",T(1.0)),
|
||||
test_ab<T>("{[('!@#$%^&*([{}])-=')]} == [{('!@#$%^&*([{}])-=')}]","","",T(1.0)),
|
||||
test_ab<T>("'1234\\\\abc\nxyz\r890\tqaz\\'567' == a","1234\\abc\nxyz\r890\tqaz'567","",T(1.0)),
|
||||
test_ab<T>("a == '1234\\\\abc\nxyz\r890\tqaz\\'567'","1234\\abc\nxyz\r890\tqaz'567","",T(1.0))
|
||||
test_ab<T>("a == '1234\\\\abc\nxyz\r890\tqaz\\'567'","1234\\abc\nxyz\r890\tqaz'567","",T(1.0)),
|
||||
test_ab<T>("'123'[] == 3" ,"","",T(1.0)),
|
||||
test_ab<T>("3 == '123'[]" ,"","",T(1.0)),
|
||||
test_ab<T>("'123'[] + '1234'[] == 7" ,"","",T(1.0)),
|
||||
test_ab<T>("abs('123'[] - '1234'[]) == 1" ,"","",T(1.0)),
|
||||
test_ab<T>("'1234'[] == a[]" ,"1234","",T(1.0)),
|
||||
test_ab<T>("'123'[] + a[] == 7" ,"1234","",T(1.0)),
|
||||
test_ab<T>("abs(a[] - '12345'[]) == 1" ,"1234","",T(1.0)),
|
||||
test_ab<T>("'1234'[] + '12345'[] == a[] + b[]" ,"1234","12345",T(1.0)),
|
||||
test_ab<T>("abs('123'[] - '1234'[]) == abs(a[] - b[])" ,"1234","12345",T(1.0))
|
||||
};
|
||||
|
||||
static const std::size_t test_list_size = sizeof(test_list) / sizeof(test_ab<T>);
|
||||
|
@ -2034,6 +2043,7 @@ inline bool run_test02()
|
|||
const std::size_t rounds = 50;
|
||||
for (std::size_t r = 0; r < rounds; ++r)
|
||||
{
|
||||
bool result = true;
|
||||
for (std::size_t i = 0; i < test_list_size; ++i)
|
||||
{
|
||||
test_ab<T>& test = const_cast<test_ab<T>&>(test_list[i]);
|
||||
|
@ -2079,10 +2089,12 @@ inline bool run_test02()
|
|||
test.expr.c_str(),
|
||||
(double)test.result,
|
||||
(double)result);
|
||||
return false;
|
||||
result = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!result)
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
@ -3293,6 +3305,124 @@ inline bool run_test10()
|
|||
"(~{ var x[3] := [1] } + ~{ var x[6] := {6,5,4,3,2,1}}) == 7",
|
||||
"(~{ var x[6] := {6,5,4,3,2,1} } + ~{ var x := 1 }) == 7",
|
||||
"(~{ var x := 1 } + ~{ var x[6] := {6,5,4,3,2,1} }) == 7",
|
||||
"var x[3] := {}; (x[0] == 0) and (x[1] == 0) and (x[2] == 0)",
|
||||
"var x[3] := {1,2}; (x[0] == 1) and (x[1] == 2) and (x[2] == 0)",
|
||||
"var x[3] := {1,2,3}; (x[0] == 1) and (x[1] == 2) and (x[2] == 3)",
|
||||
"var x[3] := [1]; (x[0] == 1) and (x[1] == 1) and (x[2] == 1)",
|
||||
"var v[3] := [1]; v += 1; (v[0] == v[1]) and (v[0] == v[2]) and (v[0] == 2)",
|
||||
"var v[3] := [1]; v -= 1; (v[0] == v[1]) and (v[0] == v[2]) and (v[0] == 0)",
|
||||
"var v[3] := [1]; v *= 2; (v[0] == v[1]) and (v[0] == v[2]) and (v[0] == 2)",
|
||||
"var v[3] := [3]; v /= 3; (v[0] == v[1]) and (v[0] == v[2]) and (v[0] == 1)",
|
||||
"var v[3] := {1,2, 3}; v += 1; (v[0] == 2) and (v[1] == 3) and (v[2] == 4)",
|
||||
"var v[3] := {1,2, 3}; v -= 1; (v[0] == 0) and (v[1] == 1) and (v[2] == 2)",
|
||||
"var v[3] := {1,2, 3}; v *= 2; (v[0] == 2) and (v[1] == 4) and (v[2] == 6)",
|
||||
"var v[3] := {3,9,15}; v /= 3; (v[0] == 1) and (v[1] == 3) and (v[2] == 5)",
|
||||
"var v0[3] := [1]; var v1[3] := [1]; v0 += v1; (v0[0] == v0[1]) and (v0[0] == v0[2]) and (v0[0] == 2)",
|
||||
"var v0[3] := [1]; var v1[3] := [1]; v0 -= v1; (v0[0] == v0[1]) and (v0[0] == v0[2]) and (v0[0] == 0)",
|
||||
"var v0[3] := [1]; var v1[3] := [2]; v0 *= v1; (v0[0] == v0[1]) and (v0[0] == v0[2]) and (v0[0] == 2)",
|
||||
"var v0[3] := [3]; var v1[3] := [3]; v0 /= v1; (v0[0] == v0[1]) and (v0[0] == v0[2]) and (v0[0] == 1)",
|
||||
"var v0[3] := {1,2, 3}; var v1[3] := {1,1,1}; v0 += v1; (v0[0] == 2) and (v0[1] == 3) and (v0[2] == 4)",
|
||||
"var v0[3] := {1,2, 3}; var v1[3] := {1,1,1}; v0 -= v1; (v0[0] == 0) and (v0[1] == 1) and (v0[2] == 2)",
|
||||
"var v0[3] := {1,2, 3}; var v1[3] := {2,2,2}; v0 *= v1; (v0[0] == 2) and (v0[1] == 4) and (v0[2] == 6)",
|
||||
"var v0[3] := {3,9,15}; var v1[3] := {3,3,3}; v0 /= v1; (v0[0] == 1) and (v0[1] == 3) and (v0[2] == 5)",
|
||||
"var x[3] := {}; var y[4] := {1,2,3,4}; x := y; (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])",
|
||||
"var x[3] := {}; var y[3] := {1,2,3}; x := y; (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])",
|
||||
"var x[3] := {}; var y[2] := {1,2}; x := y; (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == 0)",
|
||||
"var x[3] := {}; var y[1] := {1}; x := y; (x[0] == y[0]) and (x[1] == 0) and (x[2] == 0)",
|
||||
"var x[3] := {}; var y[4] := {1,2,3,4}; x := (y+=1); (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])",
|
||||
"var x[3] := {}; var y[3] := {1,2,3}; x := (y+=1); (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])",
|
||||
"var x[3] := {}; var y[2] := {1,2}; x := (y+=1); (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == 0)",
|
||||
"var x[3] := {}; var y[1] := {1}; x := (y+=1); (x[0] == y[0]) and (x[1] == 0) and (x[2] == 0)",
|
||||
"var x[3] := {}; var y[4] := {1,2,3,4}; x += (y+=1); (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])",
|
||||
"var x[3] := {}; var y[3] := {1,2,3}; x += (y+=1); (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == y[2])",
|
||||
"var x[3] := {}; var y[2] := {1,2}; x += (y+=1); (x[0] == y[0]) and (x[1] == y[1]) and (x[2] == 0)",
|
||||
"var x[3] := {}; var y[1] := {1}; x += (y+=1); (x[0] == y[0]) and (x[1] == 0) and (x[2] == 0)",
|
||||
"var x[3] := [9]; var y[4] := {1,2,3,4}; x <=> y; (x[0] == 1) and (x[1] == 2) and (x[2] == 3)",
|
||||
"var x[3] := [9]; var y[3] := {1,2,3}; x <=> y; (x[0] == 1) and (x[1] == 2) and (x[2] == 3)",
|
||||
"var x[3] := [9]; var y[2] := {1,2}; x <=> y; (x[0] == 1) and (x[1] == 2) and (x[2] == 9)",
|
||||
"var x[3] := [9]; var y[1] := {1}; x <=> y; (x[0] == 1) and (x[1] == 9) and (x[2] == 9)",
|
||||
"var x[3] := [9]; var y[4] := {1,2,3,4}; x <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 4)",
|
||||
"var x[3] := [9]; var y[3] := {1,2,3}; x <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 4)",
|
||||
"var x[3] := [9]; var y[2] := {1,2}; x <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 9)",
|
||||
"var x[3] := [9]; var y[1] := {1}; x <=> (y += 1); (x[0] == 2) and (x[1] == 9) and (x[2] == 9)",
|
||||
"var x[3] := [8]; var y[4] := {1,2,3,4}; (x += 1) <=> y; (x[0] == 1) and (x[1] == 2) and (x[2] == 3)",
|
||||
"var x[3] := [8]; var y[3] := {1,2,3}; (x += 1) <=> y; (x[0] == 1) and (x[1] == 2) and (x[2] == 3)",
|
||||
"var x[3] := [8]; var y[2] := {1,2}; (x += 1) <=> y; (x[0] == 1) and (x[1] == 2) and (x[2] == 9)",
|
||||
"var x[3] := [8]; var y[1] := {1}; (x += 1) <=> y; (x[0] == 1) and (x[1] == 9) and (x[2] == 9)",
|
||||
"var x[3] := [8]; var y[4] := {1,2,3,4}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 4)",
|
||||
"var x[3] := [8]; var y[3] := {1,2,3}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 4)",
|
||||
"var x[3] := [8]; var y[2] := {1,2}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 3) and (x[2] == 9)",
|
||||
"var x[3] := [8]; var y[1] := {1}; (x += 1) <=> (y += 1); (x[0] == 2) and (x[1] == 9) and (x[2] == 9)",
|
||||
"var x[3] := [0]; var y[4] := {1,2,3,4}; x < y",
|
||||
"var x[3] := [0]; var y[3] := {1,2,3}; x < y",
|
||||
"var x[3] := [0]; var y[2] := {1,2}; x < y",
|
||||
"var x[3] := [0]; var y[1] := {1}; x < y",
|
||||
"var x[3] := [0]; var y[4] := {1,2,3,4}; x <= y",
|
||||
"var x[3] := [0]; var y[3] := {1,2,3}; x <= y",
|
||||
"var x[3] := [0]; var y[2] := {1,2}; x <= y",
|
||||
"var x[3] := [0]; var y[1] := {1}; x <= y",
|
||||
"var x[3] := [5]; var y[4] := {1,2,3,4}; x > y",
|
||||
"var x[3] := [5]; var y[3] := {1,2,3}; x > y",
|
||||
"var x[3] := [5]; var y[2] := {1,2}; x > y",
|
||||
"var x[3] := [5]; var y[1] := {1}; x > y",
|
||||
"var x[3] := [5]; var y[4] := {1,2,3,4}; x >= y",
|
||||
"var x[3] := [5]; var y[3] := {1,2,3}; x >= y",
|
||||
"var x[3] := [5]; var y[2] := {1,2}; x >= y",
|
||||
"var x[3] := [5]; var y[1] := {1}; x >= y",
|
||||
"var x[3] := [1]; var y[4] := [1]; x == y",
|
||||
"var x[3] := [1]; var y[3] := [1]; x == y",
|
||||
"var x[3] := [1]; var y[2] := [1]; x == y",
|
||||
"var x[3] := [1]; var y[1] := [1]; x == y",
|
||||
"var x[3] := [1]; var y[4] := [2]; x != y",
|
||||
"var x[3] := [1]; var y[3] := [2]; x != y",
|
||||
"var x[3] := [1]; var y[2] := [2]; x != y",
|
||||
"var x[3] := [1]; var y[1] := [2]; x != y",
|
||||
"var x[3] := [0]; var y[4] := {5,6,7,8}; (x += 1) < y",
|
||||
"var x[3] := [0]; var y[3] := {5,6,7}; (x += 1) < y",
|
||||
"var x[3] := [0]; var y[2] := {5,6}; (x += 1) < y",
|
||||
"var x[3] := [0]; var y[1] := {5}; (x += 1) < y",
|
||||
"var x[3] := [0]; var y[4] := {1,2,3,4}; x < (y += 1)",
|
||||
"var x[3] := [0]; var y[3] := {1,2,3}; x < (y += 1)",
|
||||
"var x[3] := [0]; var y[2] := {1,2}; x < (y += 1)",
|
||||
"var x[3] := [0]; var y[1] := {1}; x < (y += 1)",
|
||||
"var x[3] := [0]; var y[4] := {5,6,7,8}; (x += 1) < (y += 1)",
|
||||
"var x[3] := [0]; var y[3] := {5,6,7}; (x += 1) < (y += 1)",
|
||||
"var x[3] := [0]; var y[2] := {5,6}; (x += 1) < (y += 1)",
|
||||
"var x[3] := [0]; var y[1] := {5}; (x += 1) < (y += 1)",
|
||||
"var x[3] := {1,2,3}; var y := 5; x < y ",
|
||||
"var x[3] := {1,2,3}; var y := 3; x < y + 1 ",
|
||||
"var x[3] := {1,2,3}; var y := 5; x <= y ",
|
||||
"var x[3] := {1,2,3}; var y := 3; x <= y + 1",
|
||||
"var x[3] := {1,1,1}; var y := 1; x == y ",
|
||||
"var x[3] := {1,1,1}; var y := 2; x == y - 1",
|
||||
"var x[3] := {1,2,3}; var y := 5; y > x ",
|
||||
"var x[3] := {1,2,3}; var y := 3; y >= x ",
|
||||
"var x[3] := {1,2,3}; var y := 5; y + 1 > x ",
|
||||
"var x[3] := {1,1,1}; var y := 1; y == x ",
|
||||
"var x[3] := {1,1,1}; var y := 2; y - 1 == x",
|
||||
"var x[3] := {1,2,3}; var y := 5; (x += 1) < y ",
|
||||
"var x[3] := {1,2,3}; var y := 3; (x -= 1) < y + 1 ",
|
||||
"var x[3] := {1,2,3}; var y := 5; (x -= 1) <= y ",
|
||||
"var x[3] := {2,2,2}; var y := 1; (x -= 1) == y ",
|
||||
"var x[3] := {1,2,3}; var y := 5; y > (x += 1) ",
|
||||
"var x[3] := {1,2,3}; var y := 5; y + 1 > (x += 1) ",
|
||||
"var x[3] := {2,2,2}; var y := 1; y == (x -= 1) ",
|
||||
"var x[3] := {2,2,2}; var y := 0; y + 1 == (x -= 1)",
|
||||
"var x[3] := [1]; var y[4] := {1,2,3,4}; var z[3] := [1]; z := (x + y); z == (x + y)",
|
||||
"var x[3] := [1]; var y[3] := {1,2,3}; var z[3] := [1]; z := (x - y); z == (x - y)",
|
||||
"var x[3] := [1]; var y[2] := {1,2}; var z[3] := [1]; z := (x / y); z == (x / y)",
|
||||
"var x[3] := [1]; var y[1] := {1}; var z[3] := [1]; z := (x * y); z == (x * y)",
|
||||
"var x[3] := [1]; var y[4] := {1,2,3,4}; var z[3] := [1]; z := 2(x + y); z == (x + y)2",
|
||||
"var x[3] := [1]; var y[3] := {1,2,3}; var z[3] := [1]; z := 2(x - y); z == (x - y)2",
|
||||
"var x[3] := [1]; var y[2] := {1,2}; var z[3] := [1]; z := 2(x / y); z == (x / y)2",
|
||||
"var x[3] := [1]; var y[1] := {1}; var z[3] := [1]; z := 2(x * y); z == (x * y)2",
|
||||
"var x[3] := [1]; var y[4] := {1,2,3,4}; var z[3] := [1]; z := 2(x + y)/3; z == 2(x + y)/3",
|
||||
"var x[3] := [1]; var y[3] := {1,2,3}; var z[3] := [1]; z := 2(x - y)/3; z == 2(x - y)/3",
|
||||
"var x[3] := [1]; var y[2] := {1,2}; var z[3] := [1]; z := 2(x / y)/3; z == 2(x / y)/3",
|
||||
"var x[3] := [1]; var y[1] := {1}; var z[3] := [1]; z := 2(x * y)/3; z == 2(x * y)/3",
|
||||
"var x[6] := {1,2,3,4,5,6}; equal(sqrt(sum([x - avg(x)]^2) / x[]),1.7078251277)",
|
||||
"var x[3] := {-1,-2,-3}; sum(abs(x) ) == 6",
|
||||
"var x[3] := {0.1,0.2,0.3}; sum(trunc(x)) == 0",
|
||||
|
||||
"var x := 2; (~{ for (i := 0; i < 10; i += 1) { for (j := 0; j <= i;"
|
||||
"j += 1) { var y := 3; if ((i + j + y + x) < 6) { y += x; continue; "
|
||||
|
@ -3322,7 +3452,7 @@ inline bool run_test10()
|
|||
|
||||
bool failed = false;
|
||||
|
||||
for (std::size_t r = 0; r < 100; ++r)
|
||||
for (std::size_t r = 0; r < 10; ++r)
|
||||
{
|
||||
for (std::size_t i = 0; i < expression_list_size; ++i)
|
||||
{
|
||||
|
@ -3346,7 +3476,6 @@ inline bool run_test10()
|
|||
{
|
||||
printf("run_test10() - swaps evaluation error Expression: %s\n",
|
||||
expression_list[i].c_str());
|
||||
|
||||
failed = true;
|
||||
}
|
||||
}
|
||||
|
|
109
readme.txt
109
readme.txt
|
@ -398,6 +398,12 @@ of C++ compilers:
|
|||
| | in the event they have fractional components truncation |
|
||||
| | will be performed. (eg: 1.67 --> 1) |
|
||||
+----------+---------------------------------------------------------+
|
||||
| [] | The string size operator returns the size of the string |
|
||||
| | being actioned. |
|
||||
| | eg: |
|
||||
| | 1. 'abc'[] == 3 |
|
||||
| | 2. var max_str_length := max(s0[],s1[],s2[],s3[]) |
|
||||
+----------+---------------------------------------------------------+
|
||||
|
||||
(6) Control Structures
|
||||
+----------+---------------------------------------------------------+
|
||||
|
@ -537,7 +543,8 @@ appropriate may represent any of one the following:
|
|||
1. Literal numeric/string value
|
||||
2. A variable
|
||||
3. A vector element
|
||||
4. An expression comprised of [1], [2] or [3] (eg: 2 + x / vec[3])
|
||||
4. A vector
|
||||
5. An expression comprised of [1], [2] or [3] (eg: 2 + x / vec[3])
|
||||
|
||||
|
||||
|
||||
|
@ -909,7 +916,58 @@ will be returned. Where as for vectors, the value of the first element
|
|||
|
||||
|
||||
|
||||
[13 - USER DEFINED FUNCTIONS]
|
||||
[13 - VECTOR PROCESSING]
|
||||
ExprTk provides support for various forms of vector oriented
|
||||
arithmetic, inequalities and processing. The various supported pairs
|
||||
are as follows:
|
||||
|
||||
(a) vector and vector (eg: v0 + v1)
|
||||
(b) vector and scalar (eg: v + 33)
|
||||
(c) scalar and vector (eg: 22 * v)
|
||||
|
||||
The following is a list of operations that can be used in conjunction
|
||||
with vectors:
|
||||
|
||||
(a) Arithmetic: +, -, *, /, %
|
||||
(b) Exponentiation: vector ^ scalar
|
||||
(c) Assignment: :=, +=, -=, *=, /=, %=
|
||||
(d) Inequalities: <, <=, >, >=, ==, =
|
||||
(e) Unary operations:
|
||||
abs, acos, acosh, asin, asinh, atan, atanh, avg, ceil,
|
||||
cos, cosh, cot, csc, deg2grad, deg2rad, erf, erfc, exp,
|
||||
expm1, floor, frac, grad2deg, log, log10, log1p, log2,
|
||||
max, min, mul, rad2deg, round, sec, sgn, sin, sinc, sinh,
|
||||
sqrt, sum, tan, tanh, trunc
|
||||
|
||||
Note: When one of the above described operations is being performed
|
||||
between two vectors, the operation will only span the size of the
|
||||
smallest vector. The elements of the larger vector outside of the
|
||||
range will not be included.
|
||||
|
||||
The following simple example demonstrates the vector processing
|
||||
capabilities by computing the dot-product of the vectors v0 and v1 and
|
||||
then assigning it to the variable v0dotv1:
|
||||
|
||||
var v0[3] := {1,2,3};
|
||||
var v1[3] := {4,5,6};
|
||||
var v0dotv1 := sum(v0 * v1);
|
||||
|
||||
|
||||
The following is a for-loop based implementation that is equivalent to
|
||||
the previously mentioned dot-product computation expression:
|
||||
|
||||
var v0[3] := {1,2,3};
|
||||
var v1[3] := {4,5,6};
|
||||
var v0dotv1;
|
||||
|
||||
for (i := 0; i < min(v0[],v1[]); i += 1)
|
||||
{
|
||||
v0dotv1 += (v0[i] * v1[i]);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[14 - USER DEFINED FUNCTIONS]
|
||||
ExprTk provides a means whereby custom functions can be defined and
|
||||
utilized within expressions. The concept requires the user to
|
||||
provide a reference to the function coupled with an associated name
|
||||
|
@ -1032,7 +1090,7 @@ calling styles are as follows:
|
|||
|
||||
|
||||
|
||||
[14 - EXPRTK NOTES]
|
||||
[15 - EXPRTK NOTES]
|
||||
The following is a list of facts and suggestions one may want to take
|
||||
into account when using Exprtk:
|
||||
|
||||
|
@ -1139,7 +1197,7 @@ into account when using Exprtk:
|
|||
|
||||
|
||||
|
||||
[15 - SIMPLE EXPRTK EXAMPLE]
|
||||
[16 - SIMPLE EXPRTK EXAMPLE]
|
||||
--- snip ---
|
||||
#include <cstdio>
|
||||
#include <string>
|
||||
|
@ -1227,7 +1285,45 @@ int main()
|
|||
|
||||
|
||||
|
||||
[16 - FILES]
|
||||
[17 - BUILD OPTIONS]
|
||||
When building ExprTk there are a number of defines that will enable or
|
||||
disable certain features and capabilities. The defines can either be
|
||||
part of a compiler command line switch or scoped around the include to
|
||||
the ExprTk header.
|
||||
|
||||
(1) exprtk_enable_debugging
|
||||
This define will enable printing of debug information during the
|
||||
compilation process.
|
||||
|
||||
(2) 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.
|
||||
|
||||
(3) 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.
|
||||
|
||||
(4) exprtk_disable_sc_andor
|
||||
This define will disable the short-circuit '&' (and) and '|' (or)
|
||||
operators
|
||||
|
||||
(5) 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.
|
||||
|
||||
(6) 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.
|
||||
|
||||
|
||||
|
||||
[18 - FILES]
|
||||
(00) Makefile
|
||||
(01) readme.txt
|
||||
(02) exprtk.hpp
|
||||
|
@ -1246,10 +1342,11 @@ int main()
|
|||
(15) exprtk_simple_example_11.cpp
|
||||
(16) exprtk_simple_example_12.cpp
|
||||
(17) exprtk_simple_example_13.cpp
|
||||
(18) exprtk_simple_example_14.cpp
|
||||
|
||||
|
||||
|
||||
[17 - LANGUAGE STRUCTURE]
|
||||
[19 - LANGUAGE STRUCTURE]
|
||||
+-------------------------------------------------------------+
|
||||
|00 - If Statement |
|
||||
| |
|
||||
|
|
Loading…
Reference in New Issue