Skip to content

Commit

Permalink
C++ Mathematical Expression Library (ExprTk) http://www.partow.net/pr…
Browse files Browse the repository at this point in the history
  • Loading branch information
ArashPartow committed Sep 26, 2016
1 parent d63c4c2 commit 5728bb1
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 26 deletions.
45 changes: 23 additions & 22 deletions exprtk.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -793,7 +793,7 @@ namespace exprtk
template <typename T>
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>
Expand Down Expand Up @@ -11123,27 +11123,28 @@ namespace exprtk
bool body_deletable_;
};

#define exprtk_define_unary_op(OpName) \
template <typename T> \
struct OpName##_op \
{ \
typedef typename functor_t<T>::Type Type; \
\
static inline T process(Type v) \
{ \
return numeric:: OpName (v); \
} \
\
static inline typename expression_node<T>::node_type type() \
{ \
return expression_node<T>::e_##OpName; \
} \
\
static inline details::operator_type operation() \
{ \
return details::e_##OpName; \
} \
}; \
#define exprtk_define_unary_op(OpName) \
template <typename T> \
struct OpName##_op \
{ \
typedef typename functor_t<T>::Type Type; \
typedef typename expression_node<T>::node_type node_t; \
\
static inline T process(Type v) \
{ \
return numeric:: OpName (v); \
} \
\
static inline node_t type() \
{ \
return expression_node<T>::e_##OpName; \
} \
\
static inline details::operator_type operation() \
{ \
return details::e_##OpName; \
} \
}; \

exprtk_define_unary_op(abs )
exprtk_define_unary_op(acos )
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_05.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ 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), y / 2)";

T x = T(1);
T y = T(2);
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_06.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ void vector_function()
std::string expression_string =
" for (var i := 0; i < min(x[],y[],z[]); i += 1) "
" { "
" z[i] := 3sin(x[i]) + 2log(y[i]); "
" z[i] := 3sin(x[i]) + 2log(y[i]); "
" } ";

T x[] = { T(1.1), T(2.2), T(3.3), T(4.4), T(5.5) };
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_08.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ void composite()
.add(
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.register_symbol_table(symbol_table);
Expand Down
2 changes: 1 addition & 1 deletion exprtk_simple_example_10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ void newton_sqrt()
" var y := x / 2; "
" repeat "
" y := (1 / 2) * (y + (x / y)); "
" if (equal(y * y,x)) "
" if (equal(y * y, x)) "
" break[y]; "
" until ((z -= 1) <= 0); "
" }; "
Expand Down

0 comments on commit 5728bb1

Please sign in to comment.