diff --git a/mrbgems/mruby-rational/src/rational.c b/mrbgems/mruby-rational/src/rational.c index 9f4475749..fff29b876 100644 --- a/mrbgems/mruby-rational/src/rational.c +++ b/mrbgems/mruby-rational/src/rational.c @@ -342,7 +342,8 @@ rational_new_f(mrb_state *mrb, mrb_float f) if (exp > 0) { mrb_int temp; - if (mrb_int_mul_overflow(nume, ((mrb_int)1)<= MRB_INT_BIT || mrb_int_mul_overflow(nume, ((mrb_int)1)<>= exp; + else if (exp < 0) { + /* exp is negative, so we need to multiply denominator by 2^(-exp) */ + int neg_exp = -exp; + if (neg_exp >= MRB_INT_BIT || mrb_int_mul_overflow(deno, ((mrb_int)1)<