mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
use NAN and INFINITY
The macro str_to_mrb_float (strto[df]) converts a string to a number, but these two macros can be used to directly get the special value. The NAN macro requires quiet NaN support, but so does str_to_mrb_float. This change also circumvents missing C99 support in Microsoft's C library. Its (or ISO C90's) strtod doesn't parse "nan" or "inf".
This commit is contained in:
+5
-5
@@ -304,8 +304,8 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
|
||||
mrb_float mod;
|
||||
|
||||
if (y == 0.0) {
|
||||
div = str_to_mrb_float("inf");
|
||||
mod = str_to_mrb_float("nan");
|
||||
div = INFINITY;
|
||||
mod = NAN;
|
||||
}
|
||||
else {
|
||||
mod = fmod(x, y);
|
||||
@@ -775,7 +775,7 @@ fix_mod(mrb_state *mrb, mrb_value x)
|
||||
mrb_int mod;
|
||||
|
||||
if (mrb_fixnum(y) == 0) {
|
||||
return mrb_float_value(mrb, str_to_mrb_float("nan"));
|
||||
return mrb_float_value(mrb, NAN);
|
||||
}
|
||||
fixdivmod(mrb, a, mrb_fixnum(y), 0, &mod);
|
||||
return mrb_fixnum_value(mod);
|
||||
@@ -805,8 +805,8 @@ fix_divmod(mrb_state *mrb, mrb_value x)
|
||||
mrb_int div, mod;
|
||||
|
||||
if (mrb_fixnum(y) == 0) {
|
||||
return mrb_assoc_new(mrb, mrb_float_value(mrb, str_to_mrb_float("inf")),
|
||||
mrb_float_value(mrb, str_to_mrb_float("nan")));
|
||||
return mrb_assoc_new(mrb, mrb_float_value(mrb, INFINITY),
|
||||
mrb_float_value(mrb, NAN));
|
||||
}
|
||||
fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod);
|
||||
return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod));
|
||||
|
||||
Reference in New Issue
Block a user