From 0166ad5798e4857e11a5facdfd12bc0289fa8f6d Mon Sep 17 00:00:00 2001 From: ZhuangYumin Date: Fri, 10 Nov 2023 11:56:14 +0800 Subject: [PATCH] fix: fix some stange point --- src/utils.cpp | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/src/utils.cpp b/src/utils.cpp index 9b596de..2675898 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -53,7 +53,7 @@ std::string Any2String(const std::any &value) { std::stringstream buf; std::string res; if (auto ptr = std::any_cast(&value)) { - buf << std::fixed << std::setprecision(310) << *ptr; + buf << std::fixed << std::setprecision(6) << *ptr; } else if (auto ptr = std::any_cast(&value)) { if (*ptr) buf << "True"; @@ -104,8 +104,12 @@ std::any DeQuate(std::any val, VariableContainer &Variables) { int ConverToSameArithType(std::any &a, std::any &b, bool allow_string_operation) { - if (std::any_cast(&a)) a = (bool)false; - if (std::any_cast(&b)) b = (bool)false; + if (std::any_cast(&a) != nullptr && + std::any_cast(&b) == nullptr) + a = (bool)false; + if (std::any_cast(&b) != nullptr && + std::any_cast(&a) == nullptr) + b = (bool)false; ZYM::int2048 *ptr_a_int2048 = std::any_cast(&a); ZYM::int2048 *ptr_b_int2048 = std::any_cast(&b); double *ptr_a_float = std::any_cast(&a); @@ -120,8 +124,6 @@ int ConverToSameArithType(std::any &a, std::any &b, "situation", 33); if (allow_string_operation && (ptr_a_string || ptr_b_string)) { - if (ptr_a_bool) a = ZYM::int2048(*ptr_a_bool); - if (ptr_b_bool) b = ZYM::int2048(*ptr_b_bool); return 1; } int level_a = (ptr_a_bool != nullptr ? 1 : 0) + @@ -149,8 +151,6 @@ int ConverToSameArithType(std::any &a, std::any &b, } std::any Add(std::any a, std::any b) { - if (std::any_cast(&a)) a = (bool)false; - if (std::any_cast(&b)) b = (bool)false; int status = ConverToSameArithType(a, b, true); bool *ptr_a_bool = std::any_cast(&a); bool *ptr_b_bool = std::any_cast(&b); @@ -160,11 +160,6 @@ std::any Add(std::any a, std::any b) { double *ptr_b_float = std::any_cast(&b); std::string *ptr_a_string = std::any_cast(&a); std::string *ptr_b_string = std::any_cast(&b); - if ((ptr_a_string != nullptr ? 1 : 0) + (ptr_b_string != nullptr ? 1 : 0) == - 1) { - throw InterpretException( - "Add: string operation not allowed in this situation", 37); - } if ((ptr_a_string != nullptr ? 1 : 0) + (ptr_b_string != nullptr ? 1 : 0) == 2) return (*ptr_a_string) + (*ptr_b_string); @@ -174,6 +169,8 @@ std::any Add(std::any a, std::any b) { return (*ptr_a_int2048) + (*ptr_b_int2048); else if ((ptr_a_float != nullptr) && (ptr_b_float != nullptr)) return (*ptr_a_float) + (*ptr_b_float); + else if ((ptr_a_string != nullptr) || (ptr_b_string != nullptr)) + return Any2String(a) + Any2String(b); else throw FatalError("Add: Type Error", 38); } @@ -228,9 +225,12 @@ std::any Mul(std::any a, std::any b) { if (*ptr_b_bool) { return *ptr_a_string; } else { - return ""; + return std::string(""); } } + if (std::any_cast(&a) != nullptr || + std::any_cast(&b) != nullptr) + return std::string(""); if (ptr_b_int2048 != nullptr) { std::string res; for (int i = 0; i < (*ptr_b_int2048); i++) res += *ptr_a_string;