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

This commit is contained in:
Yukihiro "Matz" Matsumoto
2021-03-18 15:24:31 +09:00
parent c0d63ea09f
commit a0b3378b36
+9 -8
View File
@@ -25,6 +25,7 @@
#define floor(f) floorf(f) #define floor(f) floorf(f)
#define ceil(f) ceilf(f) #define ceil(f) ceilf(f)
#define fmod(x,y) fmodf(x,y) #define fmod(x,y) fmodf(x,y)
#define copysign(x,y) copysignf(x,y)
#define FLO_TO_STR_PREC 8 #define FLO_TO_STR_PREC 8
#else #else
#define FLO_TO_STR_PREC 16 #define FLO_TO_STR_PREC 16
@@ -237,17 +238,17 @@ flo_idiv(mrb_state *mrb, mrb_value xv)
mrb_float mrb_float
mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y) mrb_num_div_flo(mrb_state *mrb, mrb_float x, mrb_float y)
{ {
mrb_float f; if (y != 0.0) {
return x / y;
if (y == 0) { }
if (x > 0) f = INFINITY; else if (x == 0.0) {
else if (x < 0) f = -INFINITY; return NAN;
else /* if (x == 0) */ f = NAN;
} }
else { 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 static mrb_value