numeric.c: use C's modulo operator if both operands are positive.

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-08-02 14:09:38 +09:00
parent a5ac9c8790
commit 6ea0c04c06
+6 -1
View File
@@ -1121,7 +1121,12 @@ int_mod(mrb_state *mrb, mrb_value x)
if (mrb_integer_p(y) && a != MRB_INT_MIN && (b=mrb_integer(y)) != MRB_INT_MIN) {
mrb_int mod;
fixdivmod(mrb, a, b, NULL, &mod);
if (a >= 0 && b >= 0) {
mod = a % b;
}
else {
fixdivmod(mrb, a, b, NULL, &mod);
}
return mrb_fixnum_value(mod);
}
#ifdef MRB_NO_FLOAT