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

This commit is contained in:
Arash Partow 2016-09-26 10:50:06 +10:00
parent 98006471f3
commit 7bc2b30e8f
5 changed files with 27 additions and 26 deletions

View File

@ -793,7 +793,7 @@ namespace exprtk
template <typename T> template <typename T>
inline T abs_impl(const T v, real_type_tag) inline T abs_impl(const T v, real_type_tag)
{ {
return ((v >= T(0)) ? v : -v); return ((v < T(0)) ? -v : v);
} }
template <typename T> template <typename T>
@ -11128,13 +11128,14 @@ namespace exprtk
struct OpName##_op \ struct OpName##_op \
{ \ { \
typedef typename functor_t<T>::Type Type; \ typedef typename functor_t<T>::Type Type; \
typedef typename expression_node<T>::node_type node_t; \
\ \
static inline T process(Type v) \ static inline T process(Type v) \
{ \ { \
return numeric:: OpName (v); \ return numeric:: OpName (v); \
} \ } \
\ \
static inline typename expression_node<T>::node_type type() \ static inline node_t type() \
{ \ { \
return expression_node<T>::e_##OpName; \ return expression_node<T>::e_##OpName; \
} \ } \

View File

@ -43,7 +43,7 @@ void custom_function()
typedef exprtk::expression<T> expression_t; typedef exprtk::expression<T> expression_t;
typedef exprtk::parser<T> parser_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), y / 2)";
T x = T(1); T x = T(1);
T y = T(2); T y = T(2);

View File

@ -49,7 +49,7 @@ void composite()
.add( .add(
function_t("g","3*[f(x) + f(y)]","x","y")); // g(x,y) = 3[f(x) + f(y)] function_t("g","3*[f(x) + f(y)]","x","y")); // g(x,y) = 3[f(x) + f(y)]
std::string expression_string = "g(1 + f(x),f(y) / 2)"; std::string expression_string = "g(1 + f(x), f(y) / 2)";
expression_t expression; expression_t expression;
expression.register_symbol_table(symbol_table); expression.register_symbol_table(symbol_table);

View File

@ -55,7 +55,7 @@ void newton_sqrt()
" var y := x / 2; " " var y := x / 2; "
" repeat " " repeat "
" y := (1 / 2) * (y + (x / y)); " " y := (1 / 2) * (y + (x / y)); "
" if (equal(y * y,x)) " " if (equal(y * y, x)) "
" break[y]; " " break[y]; "
" until ((z -= 1) <= 0); " " until ((z -= 1) <= 0); "
" }; " " }; "