numeric.c: float zero division should be infinity with sign kept; fix #5382

parent c0d63ea0
......@@ -25,6 +25,7 @@
#define floor(f) floorf(f)
#define ceil(f) ceilf(f)
#define fmod(x,y) fmodf(x,y)
#define copysign(x,y) copysignf(x,y)
#define FLO_TO_STR_PREC 8
#else
#define FLO_TO_STR_PREC 16
......@@ -237,17 +238,17 @@ flo_idiv(mrb_state *mrb, mrb_value xv)
mrb_float
mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y)
{
mrb_float f;
if (y == 0) {
if (x > 0) f = INFINITY;
else if (x < 0) f = -INFINITY;
else /* if (x == 0) */ f = NAN;
if (y != 0.0) {
return x / y;
}
else if (x == 0.0) {
return NAN;
}
else {
f = x / y;
mrb_float a = copysign(1.0, x);
mrb_float b = copysign(1.0, y);
return a * b * INFINITY;
}
return f;
}
static mrb_value
......
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