upd: fixing compare

This commit is contained in:
2023-11-10 22:57:41 +08:00
parent fff3c31206
commit bcef9b17ba

View File

@ -410,9 +410,18 @@ bool Greater(std::any a, std::any b) {
return (*ptr_a_float) > (*ptr_b_float);
else if ((ptr_a_string != nullptr) && (ptr_b_string != nullptr))
return (*ptr_a_string) > (*ptr_b_string);
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr)))
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr))) {
if (std::any_cast<NoneType>(&b) && *ptr_a_string != "") return true;
if (ptr_a_bool != nullptr) {
b = Any2Bool(b);
return int(*ptr_a_bool) > int(std::any_cast<bool>(b));
}
if (ptr_b_bool != nullptr) {
a = Any2Bool(a);
return int(std::any_cast<bool>(a)) > int(*ptr_b_bool);
}
return false;
else
} else
throw FatalError("Greater: Type Error", 54);
}
bool Less(std::any a, std::any b) {
@ -433,12 +442,25 @@ bool Less(std::any a, std::any b) {
return (*ptr_a_float) < (*ptr_b_float);
else if ((ptr_a_string != nullptr) && (ptr_b_string != nullptr))
return (*ptr_a_string) < (*ptr_b_string);
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr)))
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr))) {
if (std::any_cast<NoneType>(&a) && *ptr_b_string != "") return true;
if (ptr_a_bool != nullptr) {
b = Any2Bool(b);
return int(*ptr_a_bool) < int(std::any_cast<bool>(b));
}
if (ptr_b_bool != nullptr) {
a = Any2Bool(a);
return int(std::any_cast<bool>(a)) < int(*ptr_b_bool);
}
return false;
else
} else
throw FatalError("Less: Type Error", 55);
}
bool Equal(std::any a, std::any b) {
if ((std::any_cast<NoneType>(&a) != nullptr ? 1 : 0) +
(std::any_cast<NoneType>(&b) != nullptr ? 1 : 0) ==
1)
return false;
ConverToSameArithType(a, b, true);
bool *ptr_a_bool = std::any_cast<bool>(&a);
bool *ptr_b_bool = std::any_cast<bool>(&b);
@ -456,12 +478,24 @@ bool Equal(std::any a, std::any b) {
return (*ptr_a_float) == (*ptr_b_float);
else if ((ptr_a_string != nullptr) && (ptr_b_string != nullptr))
return (*ptr_a_string) == (*ptr_b_string);
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr)))
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr))) {
if (ptr_a_bool != nullptr) {
b = Any2Bool(b);
return int(*ptr_a_bool) == int(std::any_cast<bool>(b));
}
if (ptr_b_bool != nullptr) {
a = Any2Bool(a);
return int(std::any_cast<bool>(a)) == int(*ptr_b_bool);
}
return false;
else
} else
throw FatalError("Equal: Type Error", 56);
}
bool NotEqual(std::any a, std::any b) {
if ((std::any_cast<NoneType>(&a) != nullptr ? 1 : 0) +
(std::any_cast<NoneType>(&b) != nullptr ? 1 : 0) ==
1)
return true;
ConverToSameArithType(a, b, true);
bool *ptr_a_bool = std::any_cast<bool>(&a);
bool *ptr_b_bool = std::any_cast<bool>(&b);
@ -479,12 +513,25 @@ bool NotEqual(std::any a, std::any b) {
return (*ptr_a_float) != (*ptr_b_float);
else if ((ptr_a_string != nullptr) && (ptr_b_string != nullptr))
return (*ptr_a_string) != (*ptr_b_string);
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr)))
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr))) {
if (ptr_a_bool != nullptr) {
b = Any2Bool(b);
return int(*ptr_a_bool) != int(std::any_cast<bool>(b));
}
if (ptr_b_bool != nullptr) {
a = Any2Bool(a);
return int(std::any_cast<bool>(a)) != int(*ptr_b_bool);
}
return false;
else
} else
throw FatalError("NotEqual: Type Error", 57);
}
bool GreaterEqual(std::any a, std::any b) {
int cnt = (std::any_cast<NoneType>(&a) != nullptr ? 1 : 0) +
(std::any_cast<NoneType>(&b) != nullptr ? 1 : 0);
if (cnt == 2) return true;
if (std::any_cast<NoneType>(&a)) a = (bool)false;
if (std::any_cast<NoneType>(&b)) b = (bool)false;
ConverToSameArithType(a, b, true);
bool *ptr_a_bool = std::any_cast<bool>(&a);
bool *ptr_b_bool = std::any_cast<bool>(&b);
@ -502,12 +549,26 @@ bool GreaterEqual(std::any a, std::any b) {
return (*ptr_a_float) >= (*ptr_b_float);
else if ((ptr_a_string != nullptr) && (ptr_b_string != nullptr))
return (*ptr_a_string) >= (*ptr_b_string);
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr)))
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr))) {
if (std::any_cast<NoneType>(&b)) return true;
if (ptr_a_bool != nullptr) {
b = Any2Bool(b);
return int(*ptr_a_bool) >= int(std::any_cast<bool>(b));
}
if (ptr_b_bool != nullptr) {
a = Any2Bool(a);
return int(std::any_cast<bool>(a)) >= int(*ptr_b_bool);
}
return false;
else
} else
throw FatalError("GreaterEqual: Type Error", 58);
}
bool LessEqual(std::any a, std::any b) {
int cnt = (std::any_cast<NoneType>(&a) != nullptr ? 1 : 0) +
(std::any_cast<NoneType>(&b) != nullptr ? 1 : 0);
if (cnt == 2) return true;
if (std::any_cast<NoneType>(&a)) a = (bool)false;
if (std::any_cast<NoneType>(&b)) b = (bool)false;
ConverToSameArithType(a, b, true);
bool *ptr_a_bool = std::any_cast<bool>(&a);
bool *ptr_b_bool = std::any_cast<bool>(&b);
@ -525,8 +586,17 @@ bool LessEqual(std::any a, std::any b) {
return (*ptr_a_float) <= (*ptr_b_float);
else if ((ptr_a_string != nullptr) && (ptr_b_string != nullptr))
return (*ptr_a_string) <= (*ptr_b_string);
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr)))
else if (((ptr_a_string != nullptr) || (ptr_b_string != nullptr))) {
if (std::any_cast<NoneType>(&a)) return true;
if (ptr_a_bool != nullptr) {
b = Any2Bool(b);
return int(*ptr_a_bool) <= int(std::any_cast<bool>(b));
}
if (ptr_b_bool != nullptr) {
a = Any2Bool(a);
return int(std::any_cast<bool>(a)) <= int(*ptr_b_bool);
}
return false;
else
} else
throw FatalError("LessEqual: Type Error", 59);
}