diff --git a/exprtk.hpp b/exprtk.hpp index 32bc88c..4f67d6b 100644 --- a/exprtk.hpp +++ b/exprtk.hpp @@ -14589,7 +14589,56 @@ namespace exprtk details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); - if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),c0,v,c1,result)) + + // (c0 + v) + c1 --> (cov) (c0 + c1) + v + if ((details::e_add == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 + c1,v); + } + // (c0 + v) - c1 --> (cov) (c0 - c1) + v + else if ((details::e_add == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 - c1,v); + } + // (c0 - v) + c1 --> (cov) (c0 + c1) - v + else if ((details::e_sub == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 + c1,v); + } + // (c0 - v) - c1 --> (cov) (c0 - c1) - v + else if ((details::e_sub == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 - c1,v); + } + // (c0 * v) * c1 --> (cov) (c0 * c1) * v + else if ((details::e_mul == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 * c1,v); + } + // (c0 * v) / c1 --> (cov) (c0 / c1) * v + else if ((details::e_mul == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 / c1,v); + } + // (c0 / v) * c1 --> (cov) (c0 * c1) / v + else if ((details::e_div == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 * c1,v); + } + // (c0 / v) / c1 --> (cov) (c0 / c1) / v + else if ((details::e_div == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 / c1,v); + } + else if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),c0,v,c1,result)) return result; else if (!expr_gen.valid_operator(o0,f0)) return error_node(); @@ -14626,7 +14675,56 @@ namespace exprtk details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); - if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),c0,v,c1,result)) + + // (c0) + (v + c1) --> (cov) (c0 + c1) + v + if ((details::e_add == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 + c1,v); + } + // (c0) + (v - c1) --> (cov) (c0 - c1) + v + else if ((details::e_add == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 - c1,v); + } + // (c0) - (v + c1) --> (cov) (c0 - c1) - v + else if ((details::e_sub == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 - c1,v); + } + // (c0) - (v - c1) --> (cov) (c0 + c1) - v + else if ((details::e_sub == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 + c1,v); + } + // (c0) * (v * c1) --> (voc) v * (c0 * c1) + else if ((details::e_mul == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 * c1,v); + } + // (c0) * (v / c1) --> (cov) (c0 / c1) * v + else if ((details::e_mul == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 / c1,v); + } + // (c0) / (v * c1) --> (cov) (c0 / c1) / v + else if ((details::e_div == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 / c1,v); + } + // (c0) / (v / c1) --> (cov) (c0 * c1) / v + else if ((details::e_div == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 * c1,v); + } + else if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),c0,v,c1,result)) return result; else if (!expr_gen.valid_operator(o0,f0)) return error_node(); @@ -14673,7 +14771,56 @@ namespace exprtk details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); - if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),c0,c1,v,result)) + + // (c0) + (c1 + v) --> (cov) (c0 + c1) + v + if ((details::e_add == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 + c1,v); + } + // (c0) + (c1 - v) --> (cov) (c0 + c1) - v + else if ((details::e_add == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 + c1,v); + } + // (c0) - (c1 + v) --> (cov) (c0 - c1) - v + else if ((details::e_sub == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 - c1,v); + } + // (c0) - (c1 - v) --> (cov) (c0 - c1) + v + else if ((details::e_sub == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 - c1,v); + } + // (c0) * (c1 * v) --> (cov) (c0 * c1) * v + else if ((details::e_mul == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 * c1,v); + } + // (c0) * (c1 / v) --> (cov) (c0 * c1) / v + else if ((details::e_mul == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 * c1,v); + } + // (c0) / (c1 * v) --> (cov) (c0 / c1) / v + else if ((details::e_div == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 / c1,v); + } + // (c0) / (c1 / v) --> (cov) (c0 / c1) * v + else if ((details::e_div == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_cr > >(c0 / c1,v); + } + else if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),c0,c1,v,result)) return result; else if (!expr_gen.valid_operator(o0,f0)) return error_node(); @@ -14709,7 +14856,56 @@ namespace exprtk details::free_node(*(expr_gen.node_allocator_),branch[0]); details::free_node(*(expr_gen.node_allocator_),branch[1]); expression_node_ptr result = error_node(); - if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),v,c0,c1,result)) + + // (v + c0) + c1 --> (voc) v + (c0 + c1) + if ((details::e_add == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c0 + c1); + } + // (v + c0) - c1 --> (voc) v + (c0 - c1) + else if ((details::e_add == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c0 - c1); + } + // (v - c0) + c1 --> (voc) v - (c0 + c1) + else if ((details::e_sub == o0) && (details::e_add == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c1 - c0); + } + // (v - c0) - c1 --> (voc) v - (c0 + c1) + else if ((details::e_sub == o0) && (details::e_sub == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c0 + c1); + } + // (v * c0) * c1 --> (voc) v * (c0 * c1) + else if ((details::e_mul == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c0 * c1); + } + // (v * c0) / c1 --> (voc) v * (c0 / c1) + else if ((details::e_mul == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c0 / c1); + } + // (v / c0) * c1 --> (voc) v * (c1 / c0) + else if ((details::e_div == o0) && (details::e_mul == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c1 / c0); + } + // (v / c0) / c1 --> (voc) v / (c0 * c1) + else if ((details::e_div == o0) && (details::e_div == o1)) + { + return expr_gen.node_allocator_-> + template allocate_rc > >(v,c0 * c1); + } + else if (synthesize_sf3ext_expression::template compile(expr_gen,id(expr_gen,o0,o1),v,c0,c1,result)) return result; else if (!expr_gen.valid_operator(o0,f0)) return error_node(); @@ -18922,8 +19118,8 @@ namespace exprtk namespace information { static const char* library = "Mathematical Expression Toolkit"; - static const char* version = "2.718281828459045235360287471352662"; - static const char* date = "20130707"; + static const char* version = "2.718281828459045235360287471352662497"; + static const char* date = "20140104"; static inline std::string data() { diff --git a/exprtk_test.cpp b/exprtk_test.cpp index c8034d0..1c6685a 100644 --- a/exprtk_test.cpp +++ b/exprtk_test.cpp @@ -259,6 +259,8 @@ static const test_t test_list[] = test_t("(-7.7)",-7.7), test_t("(-8.8)",-8.8), test_t("(-9.9)",-9.9), + test_t("-(1.1)",-1.1), + test_t("-(1.1+2.2)",-3.3), test_t("1234567890",1234567890), test_t("123456789.0",123456789.0), test_t("+1234567890",1234567890),