C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
1b4e3d7cc2
commit
0d8601550f
37
exprtk.hpp
37
exprtk.hpp
|
@ -22,7 +22,7 @@
|
|||
* (07) z:=x+sin(2*pi/y) *
|
||||
* (08) u:=2*(pi*z)/(w:=x+cos(y/pi)) *
|
||||
* (09) clamp(-1,sin(2*pi*x)+cos(y/2*pi),+1) *
|
||||
* (10) inrange(-2,m,+2)==if(({-2<=m}and[m<=+2]),1,0) *
|
||||
* (10) inrange(-2,m,+2)==if(({-2<=m} and [m<=+2]),1,0) *
|
||||
* (11) (12.34sin(x)cos(2y)7+1)==(12.34*sin(x)*cos(2*y)*7+1) *
|
||||
* (12) (x ilike 's*ri?g') and [y<(3z^7+w)] *
|
||||
* *
|
||||
|
@ -1945,6 +1945,18 @@ namespace exprtk
|
|||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
inline bool is_true(const expression_node<T>* node)
|
||||
{
|
||||
return (T(0) != node->value());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_false(const expression_node<T>* node)
|
||||
{
|
||||
return (T(0) == node->value());
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_unary_node(const expression_node<T>* node)
|
||||
{
|
||||
|
@ -1981,6 +1993,22 @@ namespace exprtk
|
|||
return !is_variable_node(node);
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
class null_node : public expression_node<T>
|
||||
{
|
||||
public:
|
||||
|
||||
inline T value() const
|
||||
{
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
|
||||
inline typename expression_node<T>::node_type type() const
|
||||
{
|
||||
return expression_node<T>::e_nul;
|
||||
}
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
class literal_node : public expression_node<T>
|
||||
{
|
||||
|
@ -2450,7 +2478,7 @@ namespace exprtk
|
|||
|
||||
inline T value() const
|
||||
{
|
||||
if (test_->value() != 0)
|
||||
if (is_true(test_))
|
||||
return consequent_->value();
|
||||
else
|
||||
return alternative_->value();
|
||||
|
@ -2495,7 +2523,7 @@ namespace exprtk
|
|||
inline T value() const
|
||||
{
|
||||
T result = T(0);
|
||||
while (test_->value() != T(0))
|
||||
while (is_true(test_))
|
||||
{
|
||||
result = branch_->value();
|
||||
}
|
||||
|
@ -5351,10 +5379,7 @@ namespace exprtk
|
|||
|
||||
inline T value() const
|
||||
{
|
||||
if (expression_holder_ && expression_holder_->expr)
|
||||
return expression_holder_->expr->value();
|
||||
else
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
}
|
||||
|
||||
inline T operator()() const
|
||||
|
|
|
@ -1309,7 +1309,7 @@ inline bool run_test05()
|
|||
symbol_table.add_variable("y_var123",y);
|
||||
symbol_table.add_constants();
|
||||
|
||||
const std::size_t expression_count = 100;
|
||||
const std::size_t expression_count = 10;
|
||||
for (std::size_t i = 0; i < expression_count; ++i)
|
||||
{
|
||||
expression_t e;
|
||||
|
@ -1325,7 +1325,7 @@ inline bool run_test05()
|
|||
}
|
||||
|
||||
const T pi = T(3.14159265358979323846);
|
||||
const T increment = T(0.0001);
|
||||
const T increment = T(0.001);
|
||||
|
||||
while ((x <= T(+1000.0)) && (y <= T(+1000.0)))
|
||||
{
|
||||
|
@ -2165,13 +2165,15 @@ inline bool run_test11()
|
|||
printf("run_test11() - Error in evaluation!(1)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
expression.release();
|
||||
T result2 = expression.value();
|
||||
if (result2 == result2)
|
||||
|
||||
if (false == (!expression))
|
||||
{
|
||||
printf("run_test11() - Error in evaluation!(2)\n");
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
exprtk::parser<T> parser;
|
||||
if (!parser.compile(expression_string,expression))
|
||||
|
|
Loading…
Reference in New Issue