Permalink
Browse files

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
  • Loading branch information...
nobu committed Jul 10, 2016
1 parent 38ea561 commit 295f60b94d5ff6551fab7c55e18d1ffa6a4cf7e3
Showing with 14 additions and 0 deletions.
  1. +6 −0 ChangeLog
  2. +4 −0 test/ruby/test_sprintf.rb
  3. +4 −0 util.c
View
@@ -1,3 +1,9 @@
Sun Jul 10 14:27:25 2016 Nobuyoshi Nakada <nobu@ruby-lang.org>
* 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.
Sun Jul 10 08:57:20 2016 SHIBATA Hiroshi <hsbt@ruby-lang.org>
* thread.c: Fixed implicit conversion error with Apple clang-800.0.31
@@ -282,6 +282,10 @@ def test_float_hex
assert_equal(" 0x1.000p+0", sprintf("%20.3a", 1), bug3979)
end
def test_float_prec
assert_equal("5.03", sprintf("%.2f",5.025))
end
BSIZ = 120
def test_skip
View
4 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++;

0 comments on commit 295f60b

Please sign in to comment.