From 4d0431c5e4dc61f249b15bf952a28adec759f2e4 Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 3 Jul 2018 09:26:13 +0200 Subject: [PATCH 1/4] exprtk.hpp: fixed instantiation for integer type --- exprtk.hpp | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/exprtk.hpp b/exprtk.hpp index f55657a..7dd90e0 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -826,6 +826,12 @@ namespace exprtk return static_cast(v); } + template + inline int to_int32_impl(const T v, int_type_tag) + { + return static_cast(v); + } + template inline long long int to_int64_impl(const T v, real_type_tag) { @@ -894,7 +900,7 @@ namespace exprtk template inline T expm1_impl(const T v, int_type_tag) { - return T(std::exp(v)) - T(1); + return T(std::exp(v)) - T(1); } template @@ -1337,6 +1343,10 @@ namespace exprtk template inline T cot_impl(const T , int_type_tag) { return std::numeric_limits::quiet_NaN(); } template inline T sec_impl(const T , int_type_tag) { return std::numeric_limits::quiet_NaN(); } template inline T csc_impl(const T , int_type_tag) { return std::numeric_limits::quiet_NaN(); } + template inline T r2d_impl(const T v, int_type_tag) { return std::numeric_limits::quiet_NaN(); } + template inline T d2r_impl(const T v, int_type_tag) { return std::numeric_limits::quiet_NaN(); } + template inline T d2g_impl(const T v, int_type_tag) { return std::numeric_limits::quiet_NaN(); } + template inline T g2d_impl(const T v, int_type_tag) { return std::numeric_limits::quiet_NaN(); } template inline bool is_integer_impl(const T& v, real_type_tag) @@ -4992,6 +5002,11 @@ namespace exprtk return std::not_equal_to()(0.0,v); } + inline bool is_true(const int v) + { + return std::not_equal_to()(0,v); + } + inline bool is_true(const long double v) { return std::not_equal_to()(0.0L,v); From b4e4a1f56558ee95d07b7170aa051a29880e6aae Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 3 Jul 2018 10:18:04 +0200 Subject: [PATCH 2/4] Added is_nan_impl implementations for is_nan, to_int64, string_to_real Replaced unchecked std::copy with std::copy_n --- exprtk.hpp | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-) diff --git a/exprtk.hpp b/exprtk.hpp index 7dd90e0..e0eb192 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -820,6 +820,11 @@ namespace exprtk return std::not_equal_to()(v,v); } + template + inline bool is_nan_impl(const T v, int_type_tag) { + return std::not_equal_to()(v, v); + } + template inline int to_int32_impl(const T v, real_type_tag) { @@ -838,6 +843,11 @@ namespace exprtk return static_cast(v); } + template + inline long long int to_int64_impl(const T v, int_type_tag) { + return static_cast(v); + } + template inline bool is_true_impl(const T v) { @@ -1980,6 +1990,12 @@ namespace exprtk return true; } + template + inline bool string_to_real(Iterator& itr_external, const Iterator end, T& t, numeric::details::int_type_tag) { + numeric::details::real_type_tag rtt; + return string_to_real(itr_external, end, t, rtt); + } + template inline bool string_to_real(const std::string& s, T& t) { @@ -8564,9 +8580,9 @@ namespace exprtk { std::size_t size = std::min((s0_r1 - s0_r0),(s1_r1 - s1_r0)) + 1; - std::copy(str1_base_ptr_->base() + s1_r0, - str1_base_ptr_->base() + s1_r0 + size, - const_cast(base() + s0_r0)); + std::copy_n(str1_base_ptr_->base() + s1_r0, + size, + std::back_inserter(str0_node_ptr_->ref())); } } From 70e38fa201f9939706b3404a994fa386e691a576 Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 3 Jul 2018 15:50:23 +0200 Subject: [PATCH 3/4] Interpret integer and and or as bitwise operations --- exprtk.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/exprtk.hpp b/exprtk.hpp index e0eb192..6b092a4 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -1114,7 +1114,7 @@ namespace exprtk template inline T and_impl(const T v0, const T v1, int_type_tag) { - return v0 && v1; + return v0 & v1; } template @@ -1138,7 +1138,7 @@ namespace exprtk template inline T or_impl(const T v0, const T v1, int_type_tag) { - return (v0 || v1); + return (v0 | v1); } template From 95ff5be126489cef4b8a5837e0c2571bde735214 Mon Sep 17 00:00:00 2001 From: schoetbi Date: Tue, 3 Jul 2018 16:23:49 +0200 Subject: [PATCH 4/4] fixed shift operators << and >> --- exprtk.hpp | 58 +++++++++++++++++++++++++++++++++--------------------- 1 file changed, 36 insertions(+), 22 deletions(-) diff --git a/exprtk.hpp b/exprtk.hpp index 6b092a4..8333156 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -20496,6 +20496,8 @@ namespace exprtk case token_t::e_gt : current_state.set(e_level05,e_level06,details:: e_gt); break; case token_t::e_add : current_state.set(e_level07,e_level08,details:: e_add); break; case token_t::e_sub : current_state.set(e_level07,e_level08,details:: e_sub); break; + case token_t::e_shl : current_state.set(e_level07,e_level08,details:: e_shl); break; + case token_t::e_shr : current_state.set(e_level07,e_level08,details:: e_shr); break; case token_t::e_div : current_state.set(e_level10,e_level11,details:: e_div); break; case token_t::e_mul : current_state.set(e_level10,e_level11,details:: e_mul); break; case token_t::e_mod : current_state.set(e_level10,e_level11,details:: e_mod); break; @@ -25314,11 +25316,13 @@ namespace exprtk { expression_node_ptr branch = error_node(); - if (token_t::e_number == current_token().type) + const token_t &tk = current_token(); + const token_t::token_type token = tk.type; + if (token_t::e_number == token) { T numeric_value = T(0); - if (details::string_to_real(current_token().value, numeric_value)) + if (details::string_to_real(tk.value, numeric_value)) { expression_node_ptr literal_exp = expression_generator_(numeric_value); @@ -25326,8 +25330,8 @@ namespace exprtk { set_error( make_error(parser_error::e_numeric, - current_token(), - "ERR191 - Failed generate node for scalar: '" + current_token().value + "'", + tk, + "ERR191 - Failed generate node for scalar: '" + tk.value + "'", exprtk_error_location)); return error_node(); @@ -25340,24 +25344,24 @@ namespace exprtk { set_error( make_error(parser_error::e_numeric, - current_token(), - "ERR192 - Failed to convert '" + current_token().value + "' to a number", + tk, + "ERR192 - Failed to convert '" + tk.value + "' to a number", exprtk_error_location)); return error_node(); } } - else if (token_t::e_symbol == current_token().type) + else if (token_t::e_symbol == token) { branch = parse_symbol(); } #ifndef exprtk_disable_string_capabilities - else if (token_t::e_string == current_token().type) + else if (token_t::e_string == token) { branch = parse_const_string(); } #endif - else if (token_t::e_lbracket == current_token().type) + else if (token_t::e_lbracket == token) { next_token(); @@ -25367,8 +25371,8 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - current_token(), - "ERR193 - Expected ')' instead of: '" + current_token().value + "'", + tk, + "ERR193 - Expected ')' instead of: '" + tk.value + "'", exprtk_error_location)); free_node(node_allocator_,branch); @@ -25382,7 +25386,7 @@ namespace exprtk return error_node(); } } - else if (token_t::e_lsqrbracket == current_token().type) + else if (token_t::e_lsqrbracket == token) { next_token(); @@ -25392,8 +25396,8 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - current_token(), - "ERR194 - Expected ']' instead of: '" + current_token().value + "'", + tk, + "ERR194 - Expected ']' instead of: '" + tk.value + "'", exprtk_error_location)); free_node(node_allocator_,branch); @@ -25407,7 +25411,7 @@ namespace exprtk return error_node(); } } - else if (token_t::e_lcrlbracket == current_token().type) + else if (token_t::e_lcrlbracket == token) { next_token(); @@ -25417,8 +25421,8 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - current_token(), - "ERR195 - Expected '}' instead of: '" + current_token().value + "'", + tk, + "ERR195 - Expected '}' instead of: '" + tk.value + "'", exprtk_error_location)); free_node(node_allocator_,branch); @@ -25432,7 +25436,7 @@ namespace exprtk return error_node(); } } - else if (token_t::e_sub == current_token().type) + else if (token_t::e_sub == token) { next_token(); branch = parse_expression(e_level11); @@ -25448,16 +25452,26 @@ namespace exprtk branch = expression_generator_(details::e_neg,branch); } } - else if (token_t::e_add == current_token().type) + else if (token_t::e_add == token) { next_token(); branch = parse_expression(e_level13); } - else if (token_t::e_eof == current_token().type) + else if (token_t::e_shl == token) + { + next_token(); + branch = parse_expression(e_level13); + } + else if (token_t::e_shr == token) + { + next_token(); + branch = parse_expression(e_level13); + } + else if (token_t::e_eof == token) { set_error( make_error(parser_error::e_syntax, - current_token(), + tk, "ERR196 - Premature end of expression[1]", exprtk_error_location)); @@ -25467,7 +25481,7 @@ namespace exprtk { set_error( make_error(parser_error::e_syntax, - current_token(), + tk, "ERR197 - Premature end of expression[2]", exprtk_error_location));