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

ruby-changes:46681

From: naruse <ko1@a...>
Date: Fri, 19 May 2017 23:14:58 +0900 (JST)
Subject: [ruby-changes:46681] naruse:r58796 (trunk): Merge latest dtoa.c [Bug #13545]

naruse	2017-05-19 23:14:52 +0900 (Fri, 19 May 2017)

  New Revision: 58796

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

  Log:
    Merge latest dtoa.c [Bug #13545]
    
    Apply some part of http://www.netlib.org/fp/dtoa.c with my eyes...

  Modified files:
    trunk/test/ruby/test_float.rb
    trunk/util.c
Index: util.c
===================================================================
--- util.c	(revision 58795)
+++ util.c	(revision 58796)
@@ -2117,7 +2117,7 @@ break2: https://github.com/ruby/ruby/blob/trunk/util.c#L2117
     for (nd = nf = 0; (c = *s) >= '0' && c <= '9'; nd++, s++)
         if (nd < 9)
             y = 10*y + c - '0';
-        else if (nd < 16)
+        else if (nd < DBL_DIG + 2)
             z = 10*z + c - '0';
     nd0 = nd;
 #ifdef USE_LOCALE
@@ -2157,17 +2157,19 @@ break2: https://github.com/ruby/ruby/blob/trunk/util.c#L2157
         for (; c >= '0' && c <= '9'; c = *++s) {
 have_dig:
             nz++;
-            if (nd > DBL_DIG * 4) continue;
+            if (nd > DBL_DIG * 4) {
+		continue;
+	    }
             if (c -= '0') {
                 nf += nz;
                 for (i = 1; i < nz; i++)
                     if (nd++ < 9)
                         y *= 10;
-                    else if (nd <= DBL_DIG + 1)
+                    else if (nd <= DBL_DIG + 2)
                         z *= 10;
                 if (nd++ < 9)
                     y = 10*y + c;
-                else if (nd <= DBL_DIG + 1)
+                else if (nd <= DBL_DIG + 2)
                     z = 10*z + c;
                 nz = 0;
             }
@@ -2255,7 +2257,7 @@ ret0: https://github.com/ruby/ruby/blob/trunk/util.c#L2257
 
     if (!nd0)
         nd0 = nd;
-    k = nd < DBL_DIG + 1 ? nd : DBL_DIG + 1;
+    k = nd < DBL_DIG + 2 ? nd : DBL_DIG + 2;
     dval(rv) = y;
     if (k > 9) {
 #ifdef SET_INEXACT
Index: test/ruby/test_float.rb
===================================================================
--- test/ruby/test_float.rb	(revision 58795)
+++ test/ruby/test_float.rb	(revision 58796)
@@ -16,6 +16,8 @@ class TestFloat < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_float.rb#L16
     assert_in_delta(13.4 % 1, 0.4, 0.0001)
     assert_equal(36893488147419111424,
                  36893488147419107329.0.to_i)
+    assert_equal(1185151044158398820374743613440,
+                 1.1851510441583988e+30.to_i)
   end
 
   def nan_test(x,y)

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

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