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

This commit is contained in:
Arash Partow 2014-11-12 07:01:09 +11:00
parent d068f6e14b
commit 0392927ab3
2 changed files with 25 additions and 9 deletions

View File

@ -5080,8 +5080,10 @@ namespace exprtk
{ {
if (1 != (arg_list.size() & 1)) if (1 != (arg_list.size() & 1))
return; return;
arg_list_.resize(arg_list.size()); arg_list_.resize(arg_list.size());
delete_branch_.resize(arg_list.size()); delete_branch_.resize(arg_list.size());
for (std::size_t i = 0; i < arg_list.size(); ++i) for (std::size_t i = 0; i < arg_list.size(); ++i)
{ {
if (arg_list[i]) if (arg_list[i])
@ -5114,22 +5116,20 @@ namespace exprtk
{ {
if (!arg_list_.empty()) if (!arg_list_.empty())
{ {
if (1 != (arg_list_.size() & 1)) const std::size_t upper_bound = (arg_list_.size() - 1);
{
return std::numeric_limits<T>::quiet_NaN();
}
for (std::size_t i = 0; i < arg_list_.size() / 2; ++i) for (std::size_t i = 0; i < upper_bound; i += 2)
{ {
expression_ptr condition = arg_list_[(2 * i) ]; expression_ptr condition = arg_list_[i ];
expression_ptr consequent = arg_list_[(2 * i) + 1]; expression_ptr consequent = arg_list_[i + 1];
if (is_true(condition)) if (is_true(condition))
{ {
return consequent->value(); return consequent->value();
} }
} }
return arg_list_.back()->value(); return arg_list_[upper_bound]->value();
} }
else else
return std::numeric_limits<T>::quiet_NaN(); return std::numeric_limits<T>::quiet_NaN();

View File

@ -1252,7 +1252,23 @@ into account when using Exprtk:
8. null != null --> false 8. null != null --> false
9. null != x --> false 9. null != x --> false
(27) Every ExprTk statement is a "value returning" expression. Unlike (27) The following is a list of reserved words and symbols used by
ExprTk. Attempting to add a variable or custom function to a
symbol table using any of the reserved words will result in
a failure.
abs, acos, acosh, and, asin, asinh, atan, atan2, atanh, avg,
break, case, ceil, clamp, continue, cosh, cos, cot, csc,
default, deg2grad, deg2rad, else, equal, erfc, erf, exp,
expm1, false, floor, for, frac, grad2deg, hypot, iclamp, if,
ilike, in, inrange, in, like, log, log10, log1p, log2, logn,
mand, max, min, mod, mor, mul, nand, ncdf, nor, not,
not_equal, not, null, or, pow, rad2deg, repeat, root,
roundn, round, sec, sgn, shl, shr, sinc, sinh, sin, sqrt,
sum, swap, switch, tanh, tan, true, trunc, until, var,
while, xnor, xor, xor
(28) Every ExprTk statement is a "value returning" expression. Unlike
some languages that limit the types of expressions that can be some languages that limit the types of expressions that can be
performed in certain situations, in ExprTk any valid expression performed in certain situations, in ExprTk any valid expression
can be used in any "value consuming" context. Eg: can be used in any "value consuming" context. Eg: