diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-04 07:31:47 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2016-11-04 07:31:47 +0000 |
commit | dadd9bc24d7bdb80ee71364f1978d9344ce35dee (patch) | |
tree | dac484800ae35b2cf5c62c8d743188bc1b280a12 /util.c | |
parent | c679eb1ca96ad9b29a39a57cbff8492f817cb698 (diff) | |
download | ruby-dadd9bc24d7bdb80ee71364f1978d9344ce35dee.tar.gz |
util.c: round to even
* util.c (ruby_dtoa): round to even, instead of rounding to
nearest. [ruby-core:77864] [Bug #12889]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@56557 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r-- | util.c | 15 |
1 files changed, 8 insertions, 7 deletions
@@ -3165,7 +3165,7 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve) int bbits, b2, b5, be, dig, i, ieps, ilim, ilim0, ilim1, j, j1, k, k0, k_check, leftright, m2, m5, s2, s5, - spec_case, try_quick; + spec_case, try_quick, half = 0; Long L; #ifndef Sudden_Underflow int denorm; @@ -3452,17 +3452,17 @@ ruby_dtoa(double d_, int mode, int ndigits, int *decpt, int *sign, char **rve) ilim = i; *s++ = '0' + (int)L; if (i == ilim) { - double x; if (dval(d) > 0.5 + dval(eps)) goto bump_up; - else if (!isinf(x = d_ * tens[ilim-1] + 0.5) && - dval(d) > modf(x, &x)) - goto bump_up; else if (dval(d) < 0.5 - dval(eps)) { while (*--s == '0') ; s++; goto ret1; } + half = 1; + if ((*(s-1) - '0') & 1) { + goto bump_up; + } break; } } @@ -3770,12 +3770,13 @@ keep_dig: *s++ = '1'; goto ret; } - ++*s++; + if (!half || (*s - '0') & 1) + ++*s; } else { while (*--s == '0') ; - s++; } + s++; ret: Bfree(S); if (mhi) { |