C++ Mathematical Expression Library (ExprTk) http://www.partow.net/programming/exprtk/index.html
This commit is contained in:
parent
9a8474e7a2
commit
9836f21d07
98
exprtk.hpp
98
exprtk.hpp
|
@ -4042,40 +4042,6 @@ namespace exprtk
|
|||
return true;
|
||||
}
|
||||
|
||||
inline bool token_is_then_assign(const token_t::token_type& ttype,
|
||||
std::string& token,
|
||||
const token_advance_mode mode = e_advance)
|
||||
{
|
||||
if (current_token_.type != ttype)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
token = current_token_.value;
|
||||
|
||||
advance_token(mode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
template <typename Allocator,
|
||||
template <typename,typename> class Container>
|
||||
inline bool token_is_then_assign(const token_t::token_type& ttype,
|
||||
Container<std::string,Allocator>& token_list,
|
||||
const token_advance_mode mode = e_advance)
|
||||
{
|
||||
if (current_token_.type != ttype)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
token_list.push_back(current_token_.value);
|
||||
|
||||
advance_token(mode);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
inline bool peek_token_is(const token_t::token_type& ttype)
|
||||
{
|
||||
return (lexer_.peek_next_token().type == ttype);
|
||||
|
@ -4592,16 +4558,16 @@ namespace exprtk
|
|||
{}
|
||||
|
||||
control_block(const std::size_t& dsize)
|
||||
: ref_count(1),
|
||||
: ref_count(1 ),
|
||||
size (dsize),
|
||||
data (0),
|
||||
destruct (true)
|
||||
data (0 ),
|
||||
destruct (true )
|
||||
{ create_data(); }
|
||||
|
||||
control_block(const std::size_t& dsize, data_t dptr, bool dstrct = false)
|
||||
: ref_count(1),
|
||||
size (dsize),
|
||||
data (dptr ),
|
||||
: ref_count(1 ),
|
||||
size (dsize ),
|
||||
data (dptr ),
|
||||
destruct (dstrct)
|
||||
{}
|
||||
|
||||
|
@ -4852,19 +4818,19 @@ namespace exprtk
|
|||
case e_ne : return std::not_equal_to<T>()(arg0,arg1) ? T(1) : T(0);
|
||||
case e_gte : return (arg0 >= arg1) ? T(1) : T(0);
|
||||
case e_gt : return (arg0 > arg1) ? T(1) : T(0);
|
||||
case e_and : return and_opr<T> (arg0,arg1);
|
||||
case e_and : return and_opr <T>(arg0,arg1);
|
||||
case e_nand : return nand_opr<T>(arg0,arg1);
|
||||
case e_or : return or_opr<T> (arg0,arg1);
|
||||
case e_nor : return nor_opr<T> (arg0,arg1);
|
||||
case e_xor : return xor_opr<T> (arg0,arg1);
|
||||
case e_or : return or_opr <T>(arg0,arg1);
|
||||
case e_nor : return nor_opr <T>(arg0,arg1);
|
||||
case e_xor : return xor_opr <T>(arg0,arg1);
|
||||
case e_xnor : return xnor_opr<T>(arg0,arg1);
|
||||
case e_root : return root<T> (arg0,arg1);
|
||||
case e_roundn : return roundn<T> (arg0,arg1);
|
||||
case e_root : return root <T>(arg0,arg1);
|
||||
case e_roundn : return roundn <T>(arg0,arg1);
|
||||
case e_equal : return equal (arg0,arg1);
|
||||
case e_nequal : return nequal (arg0,arg1);
|
||||
case e_hypot : return hypot<T> (arg0,arg1);
|
||||
case e_shr : return shr<T> (arg0,arg1);
|
||||
case e_shl : return shl<T> (arg0,arg1);
|
||||
case e_hypot : return hypot <T>(arg0,arg1);
|
||||
case e_shr : return shr <T>(arg0,arg1);
|
||||
case e_shl : return shl <T>(arg0,arg1);
|
||||
|
||||
default : exprtk_debug(("numeric::details::process_impl<T> - Invalid binary operation.\n"));
|
||||
return std::numeric_limits<T>::quiet_NaN();
|
||||
|
@ -12307,14 +12273,14 @@ namespace exprtk
|
|||
static inline T process_3(const Sequence& arg_list)
|
||||
{
|
||||
return value(arg_list[0]) + value(arg_list[1]) +
|
||||
value(arg_list[2]);
|
||||
value(arg_list[2]) ;
|
||||
}
|
||||
|
||||
template <typename Sequence>
|
||||
static inline T process_4(const Sequence& arg_list)
|
||||
{
|
||||
return value(arg_list[0]) + value(arg_list[1]) +
|
||||
value(arg_list[2]) + value(arg_list[3]);
|
||||
value(arg_list[2]) + value(arg_list[3]) ;
|
||||
}
|
||||
|
||||
template <typename Sequence>
|
||||
|
@ -12322,7 +12288,7 @@ namespace exprtk
|
|||
{
|
||||
return value(arg_list[0]) + value(arg_list[1]) +
|
||||
value(arg_list[2]) + value(arg_list[3]) +
|
||||
value(arg_list[4]);
|
||||
value(arg_list[4]) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -12374,14 +12340,14 @@ namespace exprtk
|
|||
static inline T process_3(const Sequence& arg_list)
|
||||
{
|
||||
return value(arg_list[0]) * value(arg_list[1]) *
|
||||
value(arg_list[2]);
|
||||
value(arg_list[2]) ;
|
||||
}
|
||||
|
||||
template <typename Sequence>
|
||||
static inline T process_4(const Sequence& arg_list)
|
||||
{
|
||||
return value(arg_list[0]) * value(arg_list[1]) *
|
||||
value(arg_list[2]) * value(arg_list[3]);
|
||||
value(arg_list[2]) * value(arg_list[3]) ;
|
||||
}
|
||||
|
||||
template <typename Sequence>
|
||||
|
@ -12389,7 +12355,7 @@ namespace exprtk
|
|||
{
|
||||
return value(arg_list[0]) * value(arg_list[1]) *
|
||||
value(arg_list[2]) * value(arg_list[3]) *
|
||||
value(arg_list[4]);
|
||||
value(arg_list[4]) ;
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -26027,11 +25993,11 @@ namespace exprtk
|
|||
inline bool is_constpow_operation(const details::operator_type& operation, expression_node_ptr(&branch)[2])
|
||||
{
|
||||
if (
|
||||
!is_constant_node(branch[1]) ||
|
||||
is_constant_node(branch[0]) ||
|
||||
is_variable_node(branch[0]) ||
|
||||
is_vector_node (branch[0]) ||
|
||||
is_generally_string_node(branch[0])
|
||||
!details::is_constant_node(branch[1]) ||
|
||||
details::is_constant_node(branch[0]) ||
|
||||
details::is_variable_node(branch[0]) ||
|
||||
details::is_vector_node (branch[0]) ||
|
||||
details::is_generally_string_node(branch[0])
|
||||
)
|
||||
return false;
|
||||
|
||||
|
@ -27673,6 +27639,8 @@ namespace exprtk
|
|||
}
|
||||
else if (details::is_vector_elem_node(branch[0]))
|
||||
{
|
||||
lodge_assignment(e_st_vecelem,branch[0]);
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
#define case_stmt(op0,op1) \
|
||||
|
@ -27691,6 +27659,8 @@ namespace exprtk
|
|||
}
|
||||
else if (details::is_rebasevector_elem_node(branch[0]))
|
||||
{
|
||||
lodge_assignment(e_st_vecelem,branch[0]);
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
#define case_stmt(op0,op1) \
|
||||
|
@ -27709,6 +27679,8 @@ namespace exprtk
|
|||
}
|
||||
else if (details::is_rebasevector_celem_node(branch[0]))
|
||||
{
|
||||
lodge_assignment(e_st_vecelem,branch[0]);
|
||||
|
||||
switch (operation)
|
||||
{
|
||||
#define case_stmt(op0,op1) \
|
||||
|
@ -38263,9 +38235,9 @@ namespace exprtk
|
|||
namespace information
|
||||
{
|
||||
static const char* library = "Mathematical Expression Toolkit";
|
||||
static const char* version = "2.71828182845904523536028747135266249775724709369"
|
||||
"9959574966967627724076630353547594571382178525166";
|
||||
static const char* date = "20180101";
|
||||
static const char* version = "2.718281828459045235360287471352662497757247093699"
|
||||
"95957496696762772407663035354759457138217852516642";
|
||||
static const char* date = "20180913";
|
||||
|
||||
static inline std::string data()
|
||||
{
|
||||
|
|
|
@ -2452,6 +2452,11 @@ inline bool run_test02()
|
|||
test_ab<T>("var x := 'XXXXX'; var y := '01234567890'; var i := 0; x[0:i+3] <=> y[:]; (x == '0123X') and (y == 'XXXX4567890')", "","",T(1.0)),
|
||||
test_ab<T>("var x := 'XXXXX'; var y := '01234567890'; var i := 0; x[0:i+4] <=> y[:]; (x == '01234') and (y == 'XXXXX567890')", "","",T(1.0)),
|
||||
|
||||
test_ab<T>("var v[4] := {1,2,3,4}; for (var i := 0; i < v[]; i += 1) { v[i] += 10; v[i] == 0 }; sum(v) == (1 + 2 + 3 + 4) + (v[] * 10)", "","",T(1.0)),
|
||||
test_ab<T>("var v[4] := {1,2,3,4}; for (var i := 0; i < v[]; i += 1) { v[i] -= 10; v[i] == 0 }; sum(v) == (1 + 2 + 3 + 4) - (v[] * 10)", "","",T(1.0)),
|
||||
test_ab<T>("var v[4] := {1,2,3,4}; for (var i := 0; i < v[]; i += 1) { v[i] *= 10; v[i] == 0 }; sum(v) == (1 + 2 + 3 + 4) * 10", "","",T(1.0)),
|
||||
test_ab<T>("var v[4] := {1,2,3,4}; for (var i := 0; i < v[]; i += 1) { v[i] /= 10; v[i] == 0 }; sum(v) == (1 + 2 + 3 + 4) / 10", "","",T(1.0)),
|
||||
|
||||
test_ab<T>("a like b", "abcd", "abcd*", T(1.0)),
|
||||
test_ab<T>("a like b", "abcd", "abcd" , T(1.0)),
|
||||
test_ab<T>("a like b", "abcd", "abc*" , T(1.0)),
|
||||
|
|
Loading…
Reference in New Issue