diff --git a/mrbgems/mruby-complex/src/complex.c b/mrbgems/mruby-complex/src/complex.c index 126e97fec..fe1bf9bfc 100644 --- a/mrbgems/mruby-complex/src/complex.c +++ b/mrbgems/mruby-complex/src/complex.c @@ -134,9 +134,18 @@ mrb_complex_to_i(mrb_state *mrb, mrb_value self) { struct mrb_complex *p = complex_ptr(mrb, self); +#ifdef MRB_USE_BIGINT if (p->imaginary != 0) { mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Integer", self); } + if (!FIXABLE_FLOAT(p->real)) { + return mrb_bint_new_float(mrb, p->real); + } +#else + if (p->imaginary != 0 || !FIXABLE_FLOAT(p->real)) { + mrb_raisef(mrb, E_RANGE_ERROR, "can't convert %v into Integer", self); + } +#endif return mrb_int_value(mrb, (mrb_int)p->real); }