Commit f57b9d15 authored by cremno's avatar cremno

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".
parent bd4b59cd
...@@ -304,8 +304,8 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float * ...@@ -304,8 +304,8 @@ flodivmod(mrb_state *mrb, mrb_float x, mrb_float y, mrb_float *divp, mrb_float *
mrb_float mod; mrb_float mod;
if (y == 0.0) { if (y == 0.0) {
div = str_to_mrb_float("inf"); div = INFINITY;
mod = str_to_mrb_float("nan"); mod = NAN;
} }
else { else {
mod = fmod(x, y); mod = fmod(x, y);
...@@ -775,7 +775,7 @@ fix_mod(mrb_state *mrb, mrb_value x) ...@@ -775,7 +775,7 @@ fix_mod(mrb_state *mrb, mrb_value x)
mrb_int mod; mrb_int mod;
if (mrb_fixnum(y) == 0) { 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); fixdivmod(mrb, a, mrb_fixnum(y), 0, &mod);
return mrb_fixnum_value(mod); return mrb_fixnum_value(mod);
...@@ -805,8 +805,8 @@ fix_divmod(mrb_state *mrb, mrb_value x) ...@@ -805,8 +805,8 @@ fix_divmod(mrb_state *mrb, mrb_value x)
mrb_int div, mod; mrb_int div, mod;
if (mrb_fixnum(y) == 0) { if (mrb_fixnum(y) == 0) {
return mrb_assoc_new(mrb, mrb_float_value(mrb, str_to_mrb_float("inf")), return mrb_assoc_new(mrb, mrb_float_value(mrb, INFINITY),
mrb_float_value(mrb, str_to_mrb_float("nan"))); mrb_float_value(mrb, NAN));
} }
fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod); fixdivmod(mrb, mrb_fixnum(x), mrb_fixnum(y), &div, &mod);
return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod)); return mrb_assoc_new(mrb, mrb_fixnum_value(div), mrb_fixnum_value(mod));
......
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