diff --git a/mrbgems/mruby-bigint/core/bigint.c b/mrbgems/mruby-bigint/core/bigint.c index c0c5b28e8..6f5adea56 100644 --- a/mrbgems/mruby-bigint/core/bigint.c +++ b/mrbgems/mruby-bigint/core/bigint.c @@ -1180,6 +1180,9 @@ mrb_bint_div(mrb_state *mrb, mrb_value x, mrb_value y) return mrb_float_value(mrb,v1*v2); } #endif + if (mrb_integer_p(y) && mrb_integer(y) == 0) { + mrb_int_zerodiv(mrb); + } y = mrb_as_bint(mrb, y); struct RBigint *b = RBIGINT(x); struct RBigint *b2 = RBIGINT(y); diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c index 55f7412b8..126e97fec 100644 --- a/mrbgems/mruby-complex/src/complex.c +++ b/mrbgems/mruby-complex/src/complex.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #ifdef MRB_NO_FLOAT @@ -308,6 +309,9 @@ mrb_complex_div(mrb_state *mrb, mrb_value self, mrb_value rhs) a = complex_ptr(mrb, self); if (mrb_type(rhs) != MRB_TT_COMPLEX) { + if (mrb_integer_p(rhs) && mrb_integer(rhs) == 0) { + mrb_int_zerodiv(mrb); + } mrb_float f = mrb_as_float(mrb, rhs); return complex_new(mrb, mrb_div_float(a->real, f), mrb_div_float(a->imaginary, f)); } diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index 511e002e8..4ce86cd6d 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #ifndef MRB_NO_FLOAT @@ -647,6 +648,7 @@ mrb_rational_div(mrb_state *mrb, mrb_value x, mrb_value y) case MRB_TT_INTEGER: { mrb_int z = mrb_integer(y); + if (z == 0) mrb_int_zerodiv(mrb); if (mrb_int_mul_overflow(p1->denominator, z, &z)) rat_overflow(mrb); return rational_new_i(mrb, p1->numerator, z); } diff --git a/src/numeric.c b/src/numeric.c index 239492add..2870f3787 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -160,7 +160,6 @@ int_div(mrb_state *mrb, mrb_value x) #endif mrb_int a = mrb_integer(x); - if (a == 0) return mrb_fixnum_value(0); if (mrb_integer_p(y)) { return mrb_div_int_value(mrb, a, mrb_integer(y)); }