summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authorcremno <[email protected]>2014-03-08 16:38:50 +0100
committercremno <[email protected]>2014-03-08 17:25:07 +0100
commitf57b9d1576ab5a79f1fd31ad017af1f3f2517186 (patch)
treeefde77c1aea09fd6780ca59846c63069cbeb2220 /src
parentbd4b59cd043fcff8095a5c474330d66ccaf69524 (diff)
downloadmruby-f57b9d1576ab5a79f1fd31ad017af1f3f2517186.tar.gz
mruby-f57b9d1576ab5a79f1fd31ad017af1f3f2517186.zip
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".
Diffstat (limited to 'src')
-rw-r--r--src/numeric.c10
1 files changed, 5 insertions, 5 deletions
diff --git a/src/numeric.c b/src/numeric.c
index 5f23b2461..5d0269e00 100644
--- a/src/numeric.c
+++ b/src/numeric.c
@@ -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));