mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
Merge pull request #2532 from chasonr/float-to-string
Remove some roundoff from mrb_flo_to_str
This commit is contained in:
+3
-3
@@ -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++) = '.';
|
||||
|
||||
Reference in New Issue
Block a user