diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-16 08:26:39 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2014-02-17 09:40:30 +0900 |
| commit | 4b981adc585b7c6e3ce1a9d7735fedfd6887ab2f (patch) | |
| tree | 136fff58624fd9f531b2e96b296420c92f69c3b0 /src/numeric.c | |
| parent | ffe541b503033aea9adf65224408cbad1cc27d83 (diff) | |
| download | mruby-4b981adc585b7c6e3ce1a9d7735fedfd6887ab2f.tar.gz mruby-4b981adc585b7c6e3ce1a9d7735fedfd6887ab2f.zip | |
remove max_digit from mrb_flo_to_str()
Diffstat (limited to 'src/numeric.c')
| -rw-r--r-- | src/numeric.c | 23 |
1 files changed, 10 insertions, 13 deletions
diff --git a/src/numeric.c b/src/numeric.c index b5e77fed0..8dc83cc1c 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -20,6 +20,9 @@ #define floor(f) floorf(f) #define fmod(x,y) fmodf(x,y) #define pow(x,y) powf(x,y) +#define FLO_MAX_DIGITS 7 +#else +#define FLO_MAX_DIGITS 14 #endif static mrb_float @@ -104,14 +107,12 @@ num_div(mrb_state *mrb, mrb_value x) */ mrb_value -mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit) +mrb_flo_to_str(mrb_state *mrb, mrb_value flo) { mrb_float n; + int max_digits = FLO_MAX_DIGITS; - if (max_digit > 40) { - mrb_raise(mrb, E_RANGE_ERROR, "Too large max_digit."); - } - else if (!mrb_float_p(flo)) { + if (!mrb_float_p(flo)) { mrb_raise(mrb, E_TYPE_ERROR, "non float value"); } @@ -143,7 +144,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit) exp = (n > 1) ? floor(log10(n)) : -ceil(-log10(n)); - if ((exp < 0 ? -exp : exp) >= max_digit) { + if ((exp < 0 ? -exp : exp) >= FLO_MAX_DIGITS) { /* exponent representation */ e = TRUE; n = n / pow(10.0, exp); @@ -156,7 +157,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit) } /* puts digits */ - while (max_digit >= 0) { + while (max_digits >= 0) { mrb_float weight = pow(10.0, m); mrb_float fdigit = n / weight; @@ -174,7 +175,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit) } *(c++) = '0' + digit; n -= (digit * weight); - max_digit--; + max_digits--; if (m-- == 0) { *(c++) = '.'; } @@ -219,11 +220,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_value flo, int max_digit) static mrb_value flo_to_s(mrb_state *mrb, mrb_value flt) { -#ifdef MRB_USE_FLOAT - return mrb_flo_to_str(mrb, flt, 7); -#else - return mrb_flo_to_str(mrb, flt, 14); -#endif + return mrb_flo_to_str(mrb, flt); } /* 15.2.9.3.2 */ |
