diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-02 14:09:38 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-02 14:09:38 +0900 |
| commit | 6ea0c04c0616e55de93e77ba45b9d9933b9460e8 (patch) | |
| tree | b78881f4dce00a0ff405e4763124ca9abb5d21e7 | |
| parent | a5ac9c8790adcab48a49adb61ec9b4a9bc65d770 (diff) | |
| download | mruby-6ea0c04c0616e55de93e77ba45b9d9933b9460e8.tar.gz mruby-6ea0c04c0616e55de93e77ba45b9d9933b9460e8.zip | |
numeric.c: use C's modulo operator if both operands are positive.
| -rw-r--r-- | src/numeric.c | 7 |
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 |
