upd: allow 0 in mod
This commit is contained in:
@ -304,6 +304,7 @@ std::any Divv(std::any a, std::any b) {
|
||||
std::any Mod(std::any a, std::any b) {
|
||||
if (std::any_cast<NoneType>(&a)) a = (bool)false;
|
||||
if (std::any_cast<NoneType>(&b)) b = (bool)false;
|
||||
if (std::any_cast<std::string>(&a) != nullptr) a = ZYM::int2048(0);
|
||||
ConverToSameArithType(a, b);
|
||||
bool *ptr_a_bool = std::any_cast<bool>(&a);
|
||||
bool *ptr_b_bool = std::any_cast<bool>(&b);
|
||||
@ -312,18 +313,17 @@ std::any Mod(std::any a, std::any b) {
|
||||
double *ptr_a_float = std::any_cast<double>(&a);
|
||||
double *ptr_b_float = std::any_cast<double>(&b);
|
||||
if ((ptr_a_float != nullptr) && (ptr_b_float != nullptr)) {
|
||||
if ((*ptr_b_float) == 0)
|
||||
throw InterpretException("Mod: divided by zero", 49);
|
||||
return ZYM::int2048((*ptr_a_float) -
|
||||
(*ptr_b_float) *
|
||||
std::floor((*ptr_a_float) / (*ptr_b_float)));
|
||||
// if ((*ptr_b_float) == 0)
|
||||
// throw InterpretException("Mod: divided by zero", 49);
|
||||
return (*ptr_a_float) -
|
||||
(*ptr_b_float) * std::floor((*ptr_a_float) / (*ptr_b_float));
|
||||
} else if ((ptr_a_int2048 != nullptr) && (ptr_b_int2048 != nullptr)) {
|
||||
if ((*ptr_b_int2048) == 0)
|
||||
throw InterpretException("Mod: divided by zero", 50);
|
||||
// if ((*ptr_b_int2048) == 0)
|
||||
// throw InterpretException("Mod: divided by zero", 50);
|
||||
return (*ptr_a_int2048) % (*ptr_b_int2048);
|
||||
} else if ((ptr_a_bool != nullptr) && (ptr_b_bool != nullptr)) {
|
||||
if ((*ptr_b_bool) == 0)
|
||||
throw InterpretException("Mod: divided by zero", 51);
|
||||
// if ((*ptr_b_bool) == 0)
|
||||
// throw InterpretException("Mod: divided by zero", 51);
|
||||
return ZYM::int2048(int(*ptr_a_bool) % int(*ptr_b_bool));
|
||||
} else
|
||||
throw FatalError("Mod: Type Error", 52);
|
||||
|
Reference in New Issue
Block a user