numeric.c: avoid integer overflow; close
Since `mruby` does not have `Bignum`, `Float#divmod` could overflow, so
it will return `Float` values when the divided value does not fit in
`mrb_int`. This behavior will be changed when `Bignum` is introduced to
`mruby` in the future.
@@ -1016,6 +1016,9 @@ flo_divmod(mrb_state *mrb, mrb_value x)
mrb_value a, b;
flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
+ if (!FIXABLE_FLOAT(div))
+ a = mrb_float_value(mrb, div);
+ else
a = mrb_int_value(mrb, (mrb_int)div);
b = mrb_float_value(mrb, mod);
return mrb_assoc_new(mrb, a, b);
