summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-04 07:31:47 (GMT)
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-11-04 07:31:47 (GMT)
commit6ed8c79ddb11ccfb580bb0a22b22cc1362250255 (patch)
treedac484800ae35b2cf5c62c8d743188bc1b280a12 /util.c
parent25728a1963a89940c26879cacb5f33741fd68455 (diff)
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.c15
1 files changed, 8 insertions, 7 deletions
diff --git a/util.c b/util.c
index 17819e5..b118bdf 100644
--- a/util.c
+++ b/util.c
@@ -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) {