diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-06 11:16:12 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2021-08-06 11:16:12 +0900 |
| commit | 46a1c40fe34a935b3e942d8c5aca958df6c02c3f (patch) | |
| tree | 111bca020fdb3a61b8ebc1b0697e84273e75db45 /mrbgems/mruby-numeric-ext | |
| parent | ff2da0b66e38bc55a04149d8012e85984202f121 (diff) | |
| download | mruby-46a1c40fe34a935b3e942d8c5aca958df6c02c3f.tar.gz mruby-46a1c40fe34a935b3e942d8c5aca958df6c02c3f.zip | |
numeric_ext.c: fix a bug regarding `MRB_INT_MIN`.
Diffstat (limited to 'mrbgems/mruby-numeric-ext')
| -rw-r--r-- | mrbgems/mruby-numeric-ext/src/numeric_ext.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/mrbgems/mruby-numeric-ext/src/numeric_ext.c b/mrbgems/mruby-numeric-ext/src/numeric_ext.c index 59b51d092..38d297374 100644 --- a/mrbgems/mruby-numeric-ext/src/numeric_ext.c +++ b/mrbgems/mruby-numeric-ext/src/numeric_ext.c @@ -72,20 +72,20 @@ int_remainder(mrb_state *mrb, mrb_value x) mrb_int a, b; a = mrb_integer(x); - if (mrb_integer_p(y) && a != MRB_INT_MIN && (b=mrb_integer(y)) != MRB_INT_MIN) { + if (mrb_integer_p(y)) { + b = mrb_integer(y); if (b == 0) zerodiv(mrb); + if (a == MRB_INT_MIN && b == -1) return mrb_fixnum_value(0); return mrb_int_value(mrb, a % b); } #ifdef MRB_NO_FLOAT mrb_raise(mrb, E_TYPE_ERROR, "non integer remainder"); #else - else { - mrb_float n = (mrb_float)a; - mrb_float m = mrb_as_float(mrb, y); + mrb_float n = (mrb_float)a; + mrb_float m = mrb_as_float(mrb, y); - if (isinf(m)) return mrb_float_value(mrb, n); - return mrb_float_value(mrb, n-m*trunc(n/m)); - } + if (isinf(m)) return mrb_float_value(mrb, n); + return mrb_float_value(mrb, n-m*trunc(n/m)); #endif } |
