Float values divided by zero should honor signs; fix #3766

It also fixes unexpected resurrection of #3745 by #3752
parent 84945570
......@@ -187,12 +187,9 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
mrb_float mod;
if (y == 0.0) {
if (x == 0.0) {
div = NAN;
}
else {
div = INFINITY;
}
if (x == 0.0) div = NAN;
else if (x > 0.0) div = INFINITY;
else if (x < 0.0) div = -INFINITY;
mod = NAN;
}
else {
......
......@@ -2389,8 +2389,10 @@ RETRY_TRY_BLOCK:
mrb_int x = mrb_fixnum(regs[a]);
mrb_int y = mrb_fixnum(regs[a+1]);
double f;
if (y == 0 && x != 0) {
f = INFINITY;
if (y == 0) {
if (x == 0) f = NAN;
else if (x > 0) f = INFINITY;
else if (x < 0) f = -INFINITY;
}
else {
f = (mrb_float)x / (mrb_float)y;
......
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