mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Float values divided by zero should honor signs; fix #3766
It also fixes unexpected resurrection of #3745 by #3752
This commit is contained in:
+3
-6
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user