`(0.0).div(0)` should not be infinity; fix #3753

parent 9fa3d771
......@@ -187,7 +187,12 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
mrb_float mod;
if (y == 0.0) {
div = INFINITY;
if (x == 0.0) {
div = NAN;
}
else {
div = INFINITY;
}
mod = NAN;
}
else {
......@@ -811,8 +816,10 @@ fix_divmod(mrb_state *mrb, mrb_value x)
mrb_int div, mod;
if (mrb_fixnum(y) == 0) {
return mrb_assoc_new(mrb, mrb_float_value(mrb, INFINITY),
mrb_float_value(mrb, NAN));
return mrb_assoc_new(mrb, ((mrb_fixnum(x) == 0) ?
mrb_float_value(mrb, NAN):
mrb_float_value(mrb, INFINITY)),
mrb_float_value(mrb, NAN));
}
fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod);
return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod));
......@@ -838,7 +845,7 @@ flo_divmod(mrb_state *mrb, mrb_value x)
mrb_get_args(mrb, "o", &y);
flodivmod(mrb, mrb_float(x), mrb_to_flo(mrb, y), &div, &mod);
a = mrb_float_value(mrb, (mrb_int)div);
a = mrb_float_value(mrb, div);
b = mrb_float_value(mrb, mod);
return mrb_assoc_new(mrb, a, b);
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment