[前][次][番号順一覧][スレッド一覧]

ruby-changes:43548

From: nobu <ko1@a...>
Date: Sun, 10 Jul 2016 14:27:32 +0900 (JST)
Subject: [ruby-changes:43548] nobu:r55621 (trunk): util.c: round nearly middle value

nobu	2016-07-10 14:27:27 +0900 (Sun, 10 Jul 2016)

  New Revision: 55621

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=55621

  Log:
    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.

  Modified files:
    trunk/ChangeLog
    trunk/test/ruby/test_sprintf.rb
    trunk/util.c
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 55620)
+++ ChangeLog	(revision 55621)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jul 10 14:27:25 2016  Nobuyoshi Nakada  <nobu@r...>
+
+	* 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@r...>
 
 	* thread.c: Fixed implicit conversion error with Apple clang-800.0.31
Index: test/ruby/test_sprintf.rb
===================================================================
--- test/ruby/test_sprintf.rb	(revision 55620)
+++ test/ruby/test_sprintf.rb	(revision 55621)
@@ -282,6 +282,10 @@ class TestSprintf < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_sprintf.rb#L282
     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
Index: util.c
===================================================================
--- util.c	(revision 55620)
+++ util.c	(revision 55621)
@@ -3452,8 +3452,12 @@ ruby_dtoa(double d_, int mode, int ndigi https://github.com/ruby/ruby/blob/trunk/util.c#L3452
                     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++;

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]