diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-17 10:20:58 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-17 10:20:58 +0900 |
| commit | 57b7f6b6198b54abe822b521e4026fc3992f2a25 (patch) | |
| tree | 594fe06586af9201223ff512ba87b903504a2710 /src/numeric.c | |
| parent | eacdcc13d81eb4ff418fb99acc8e438d1dd838a3 (diff) | |
| download | mruby-57b7f6b6198b54abe822b521e4026fc3992f2a25.tar.gz mruby-57b7f6b6198b54abe822b521e4026fc3992f2a25.zip | |
use double instead of mrb_float (that may be single precision float) to reduce errors
Diffstat (limited to 'src/numeric.c')
| -rw-r--r-- | src/numeric.c | 9 |
1 files changed, 4 insertions, 5 deletions
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) { |
