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

ruby-changes:25510

From: mrkn <ko1@a...>
Date: Fri, 9 Nov 2012 07:38:30 +0900 (JST)
Subject: [ruby-changes:25510] mrkn:r37567 (trunk): * bignum.c (bigmul0): enable big_mul_toom3.

mrkn	2012-11-09 07:38:03 +0900 (Fri, 09 Nov 2012)

  New Revision: 37567

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=37567

  Log:
    * bignum.c (bigmul0): enable big_mul_toom3.
      [ruby-core:48552] [Bug #7242]
    
    * bignum.c (bigmul1_toom3): fix incorrect calculation.
      the patch is made by Heesob Park.
      [ruby-core:48552] [Bug #7242]

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c
    trunk/test/ruby/test_bignum.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 37566)
+++ ChangeLog	(revision 37567)
@@ -1,8 +1,17 @@
-Thu Nov  9 05:33:99 2012  Kenta Murata  <mrkn@m...>
+Thu Nov  9 07:36:00 2012  Kenta Murata  <mrkn@m...>
 
-	* bignum.c (bigmul0): disable big_mul_toom3_temporalily.
+	* bignum.c (bigmul0): enable big_mul_toom3.
 	  [ruby-core:48552] [Bug #7242]
 
+	* bignum.c (bigmul1_toom3): fix incorrect calculation.
+	  the patch is made by Heesob Park.
+	  [ruby-core:48552] [Bug #7242]
+
+Thu Nov  9 05:33:00 2012  Kenta Murata  <mrkn@m...>
+
+	* bignum.c (bigmul0): disable big_mul_toom3 temporalily.
+	  [ruby-core:48552] [Bug #7242]
+
 	* test/ruby/test_bignum.rb (test_mul_large_numbers):
 	  add a test for bigmul1_toom3 suggested in [Bug #7242].
 
Index: bignum.c
===================================================================
--- bignum.c	(revision 37566)
+++ bignum.c	(revision 37567)
@@ -2501,7 +2501,7 @@
     z2 = bigtrunc(bigadd(u2, u0, 0));
 
     /* z3 <- (z2 - z3) / 2 + 2 * z(inf) == (z2 - z3) / 2 + 2 * u4 */
-    z3 = bigadd(z2, z3, 0);
+    z3 = bigtrunc(bigadd(z2, z3, 0));
     bigrsh_bang(BDIGITS(z3), RBIGNUM_LEN(z3), 1);
     t = big_lshift(u4, 1); /* TODO: combining with next addition */
     z3 = bigtrunc(bigadd(z3, t, 1));
@@ -2617,8 +2617,13 @@
     /* balance multiplication by slicing y when x is much smaller than y */
     if (2 * xn <= yn) return bigmul1_balance(x, y);
 
-    /* multiplication by karatsuba method */
-    return bigmul1_karatsuba(x, y);
+    if (xn < TOOM3_MUL_DIGITS) {
+	/* multiplication by karatsuba method */
+	return bigmul1_karatsuba(x, y);
+    }
+    else if (3*xn <= 2*(yn + 2))
+	return bigmul1_balance(x, y);
+    return bigmul1_toom3(x, y);
 }
 
 /*
Index: test/ruby/test_bignum.rb
===================================================================
--- test/ruby/test_bignum.rb	(revision 37566)
+++ test/ruby/test_bignum.rb	(revision 37567)
@@ -292,7 +292,6 @@
       69131640408147806442422254638590386673344704147156793990832671592488742473
       31524606724894164324227362735271650556732855509929890983919463699819116427
     ].join.to_i
-
     b = %w[
       31519454770031243652776765515030872050264386564379909299874378289835540661
       99756262835346828114038365624177182230027040172583473561802565238817167503
@@ -372,7 +371,7 @@
       21851731257845562153822058534043916834839514338448582518847879059020959697
       90538105704766415685100946308842788321400392381169436435078204622400475281
     ].join.to_i
-    assert_equal(c, a*b)
+    assert_equal(c, a*b, '[ruby-core:48552]')
   end
 
   def test_divrem

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

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