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

This commit is contained in:
Arash Partow 2016-10-26 17:01:09 +11:00
parent 08e141b720
commit f75c3934ed
1 changed files with 9 additions and 1 deletions

View File

@ -36,6 +36,12 @@ struct myfunc : public exprtk::ifunction<T>
}
};
template <typename T>
inline T myotherfunc(T v0, T v1, T v2)
{
return std::abs(v0 - v1) * v2;
}
template <typename T>
void custom_function()
{
@ -43,7 +49,8 @@ void custom_function()
typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_t;
std::string expression_string = "myfunc(sin(x * pi), y / 2)";
std::string expression_string =
"myfunc(sin(x / pi), otherfunc(3 * y, x / 2, x * y))";
T x = T(1);
T y = T(2);
@ -53,6 +60,7 @@ void custom_function()
symbol_table.add_variable("x",x);
symbol_table.add_variable("y",y);
symbol_table.add_function("myfunc",mf);
symbol_table.add_function("otherfunc",myotherfunc);
symbol_table.add_constants();
expression_t expression;