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

It also fixes unexpected resurrection of #3745 by #3752
This commit is contained in:
Yukihiro "Matz" Matsumoto
2017-08-08 02:13:11 +09:00
parent 8494557006
commit 66e2928bd4
2 changed files with 7 additions and 8 deletions
+3 -6
View File
@@ -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 {
+4 -2
View File
@@ -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;