From 89b0c7d7abd1aa8ed05445b6530a6b746c159912 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Sat, 30 Jul 2022 08:44:15 +0900 Subject: [PATCH] complex.c (mrb_complex_to_i): return bigint if possible. --- mrbgems/mruby-complex/src/complex.c | 9 +++++++++ 1 file changed, 9 insertions(+) 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); }