From f75c3934ed3c93a94794e8c9223c7418092d6433 Mon Sep 17 00:00:00 2001 From: Arash Partow Date: Wed, 26 Oct 2016 17:01:09 +1100 Subject: [PATCH] C++ Mathematical Expression Library (ExprTk) https://www.partow.net/programming/exprtk/index.html --- exprtk_simple_example_05.cpp | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/exprtk_simple_example_05.cpp b/exprtk_simple_example_05.cpp index 939b765..723bea3 100644 --- a/exprtk_simple_example_05.cpp +++ b/exprtk_simple_example_05.cpp @@ -36,6 +36,12 @@ struct myfunc : public exprtk::ifunction } }; +template +inline T myotherfunc(T v0, T v1, T v2) +{ + return std::abs(v0 - v1) * v2; +} + template void custom_function() { @@ -43,7 +49,8 @@ void custom_function() typedef exprtk::expression expression_t; typedef exprtk::parser 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;