diff options
| author | chasonr <[email protected]> | 2014-08-13 23:31:22 -0400 |
|---|---|---|
| committer | chasonr <[email protected]> | 2014-08-13 23:31:22 -0400 |
| commit | f7389bb1e62326c9f42f9e6092c909dcbbfd9203 (patch) | |
| tree | e9376e586cf8675a0102365feb9dfbd640543234 /src/numeric.c | |
| parent | 6c1dfc95669ca6c39685184c58760acc9f799d64 (diff) | |
| download | mruby-f7389bb1e62326c9f42f9e6092c909dcbbfd9203.tar.gz mruby-f7389bb1e62326c9f42f9e6092c909dcbbfd9203.zip | |
Remove some roundoff from mrb_flo_to_str
Diffstat (limited to 'src/numeric.c')
| -rw-r--r-- | src/numeric.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/src/numeric.c b/src/numeric.c index 043dfa1f5..41ffe5fcf 100644 --- a/src/numeric.c +++ b/src/numeric.c @@ -188,8 +188,8 @@ mrb_flo_to_str(mrb_state *mrb, mrb_float flo) /* puts digits */ while (max_digits >= 0) { - double weight = pow(10.0, m); - double fdigit = n / weight; + double weight = (m < 0) ? 0.0 : pow(10.0, m); + double fdigit = (m < 0) ? n * 10.0 : n / weight; if (fdigit < 0) fdigit = n = 0; if (m < -1 && fdigit < FLO_EPSILON) { @@ -204,7 +204,7 @@ mrb_flo_to_str(mrb_state *mrb, mrb_float flo) continue; } *(c++) = '0' + digit; - n -= (digit * weight); + n = (m < 0) ? n * 10.0 - digit : n - (digit * weight); max_digits--; if (m-- == 0) { *(c++) = '.'; |
