fix: fix some stange point
This commit is contained in:
@ -53,7 +53,7 @@ std::string Any2String(const std::any &value) {
|
||||
std::stringstream buf;
|
||||
std::string res;
|
||||
if (auto ptr = std::any_cast<double>(&value)) {
|
||||
buf << std::fixed << std::setprecision(310) << *ptr;
|
||||
buf << std::fixed << std::setprecision(6) << *ptr;
|
||||
} else if (auto ptr = std::any_cast<bool>(&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<NoneType>(&a)) a = (bool)false;
|
||||
if (std::any_cast<NoneType>(&b)) b = (bool)false;
|
||||
if (std::any_cast<NoneType>(&a) != nullptr &&
|
||||
std::any_cast<std::string>(&b) == nullptr)
|
||||
a = (bool)false;
|
||||
if (std::any_cast<NoneType>(&b) != nullptr &&
|
||||
std::any_cast<std::string>(&a) == nullptr)
|
||||
b = (bool)false;
|
||||
ZYM::int2048 *ptr_a_int2048 = std::any_cast<ZYM::int2048>(&a);
|
||||
ZYM::int2048 *ptr_b_int2048 = std::any_cast<ZYM::int2048>(&b);
|
||||
double *ptr_a_float = std::any_cast<double>(&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<NoneType>(&a)) a = (bool)false;
|
||||
if (std::any_cast<NoneType>(&b)) b = (bool)false;
|
||||
int status = ConverToSameArithType(a, b, true);
|
||||
bool *ptr_a_bool = std::any_cast<bool>(&a);
|
||||
bool *ptr_b_bool = std::any_cast<bool>(&b);
|
||||
@ -160,11 +160,6 @@ std::any Add(std::any a, std::any b) {
|
||||
double *ptr_b_float = std::any_cast<double>(&b);
|
||||
std::string *ptr_a_string = std::any_cast<std::string>(&a);
|
||||
std::string *ptr_b_string = std::any_cast<std::string>(&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<NoneType>(&a) != nullptr ||
|
||||
std::any_cast<NoneType>(&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;
|
||||
|
Reference in New Issue
Block a user