summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2021-08-02 14:09:38 +0900
committerYukihiro "Matz" Matsumoto <[email protected]>2021-08-02 14:09:38 +0900
commit6ea0c04c0616e55de93e77ba45b9d9933b9460e8 (patch)
treeb78881f4dce00a0ff405e4763124ca9abb5d21e7 /src
parenta5ac9c8790adcab48a49adb61ec9b4a9bc65d770 (diff)
downloadmruby-6ea0c04c0616e55de93e77ba45b9d9933b9460e8.tar.gz
mruby-6ea0c04c0616e55de93e77ba45b9d9933b9460e8.zip
numeric.c: use C's modulo operator if both operands are positive.
Diffstat (limited to 'src')
-rw-r--r--src/numeric.c7
1 files changed, 6 insertions, 1 deletions
diff --git a/src/numeric.c b/src/numeric.c
index ab6632e52..b8e207a74 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -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