From 57b7f6b6198b54abe822b521e4026fc3992f2a25 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Mon, 17 Feb 2014 10:20:58 +0900 Subject: use double instead of mrb_float (that may be single precision float) to reduce errors --- src/numeric.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) (limited to 'src/numeric.c') diff --git a/src/numeric.c b/src/numeric.c index 18dd1e5bf..0789a7654 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -18,7 +18,6 @@ #define floor(f) floorf(f) #define ceil(f) ceilf(f) #define fmod(x,y) fmodf(x,y) -#define pow(x,y) powf(x,y) #define FLO_MAX_DIGITS 7 #define FLO_EPSILON FLT_EPSILON #else @@ -110,14 +109,14 @@ num_div(mrb_state *mrb, mrb_value x) mrb_value mrb_flo_to_str(mrb_state *mrb, mrb_value flo) { - mrb_float n; + double n; int max_digits = FLO_MAX_DIGITS; if (!mrb_float_p(flo)) { mrb_raise(mrb, E_TYPE_ERROR, "non float value"); } - n = mrb_float(flo); + n = (double)mrb_float(flo); if (isnan(n)) { return mrb_str_new_lit(mrb, "NaN"); @@ -159,8 +158,8 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo) /* puts digits */ while (max_digits >= 0) { - mrb_float weight = pow(10.0, m); - mrb_float fdigit = n / weight; + double weight = pow(10.0, m); + double fdigit = n / weight; if (fdigit < 0) fdigit = n = 0; if (m < -1 && fdigit < FLO_EPSILON) { -- cgit v1.2.3