aboutsummaryrefslogtreecommitdiffstats
path: root/util.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-10 05:27:27 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-07-10 05:27:27 +0000
commit295f60b94d5ff6551fab7c55e18d1ffa6a4cf7e3 (patch)
treeb8f7a15df7947c84aefedad4af07460dc5399b7a /util.c
parent38ea561319864fecf92bc61af0d9b9b1f49df6a0 (diff)
downloadruby-295f60b94d5ff6551fab7c55e18d1ffa6a4cf7e3.tar.gz
util.c: round nearly middle value
* util.c (ruby_dtoa): [EXPERIMENTAL] adjust the case that the Float value is close to the exact but unrepresentable middle value of two values in the given precision, as r55604. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55621 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'util.c')
-rw-r--r--util.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/util.c b/util.c
index 8c428b57f0..0b0c935832 100644
--- a/util.c
+++ b/util.c
@@ -3452,8 +3452,12 @@ 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++;