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

ruby-changes:28952

From: akr <ko1@a...>
Date: Fri, 31 May 2013 23:25:21 +0900 (JST)
Subject: [ruby-changes:28952] akr:r41004 (trunk): * bignum.c: Don't hard code SIZEOF_BDIGITS for log_base(hbase).

akr	2013-05-31 23:24:31 +0900 (Fri, 31 May 2013)

  New Revision: 41004

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

  Log:
    * bignum.c: Don't hard code SIZEOF_BDIGITS for log_base(hbase).
      (big2str_orig): hbase_numdigits argument added.
      (big2str_karatsuba): Ditto.
      (rb_big2str0): Calculate hbase_numdigits.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41003)
+++ ChangeLog	(revision 41004)
@@ -1,3 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Fri May 31 23:22:24 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c: Don't hard code SIZEOF_BDIGITS for log_base(hbase).
+	  (big2str_orig): hbase_numdigits argument added.
+	  (big2str_karatsuba): Ditto.
+	  (rb_big2str0): Calculate hbase_numdigits.
+
 Fri May 31 17:57:21 2013  Zachary Scott  <zachary@z...>
 
 	* process.c: Improve Process::exec documentation
Index: bignum.c
===================================================================
--- bignum.c	(revision 41003)
+++ bignum.c	(revision 41004)
@@ -1055,7 +1055,7 @@ big2str_find_n1(VALUE x, int base) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1055
 }
 
 static long
-big2str_orig(VALUE x, int base, char* ptr, long len, long hbase, int trim)
+big2str_orig(VALUE x, int base, char* ptr, long len, long hbase, int hbase_numdigits, int trim)
 {
     long i = RBIGNUM_LEN(x), j = len;
     BDIGIT* ds = BDIGITS(x);
@@ -1070,7 +1070,7 @@ big2str_orig(VALUE x, int base, char* pt https://github.com/ruby/ruby/blob/trunk/bignum.c#L1070
 	    num %= hbase;
 	}
 	if (trim && ds[i-1] == 0) i--;
-	k = SIZEOF_BDIGITS;
+	k = hbase_numdigits;
 	while (k--) {
 	    ptr[--j] = ruby_digitmap[num % base];
 	    num /= base;
@@ -1088,7 +1088,7 @@ big2str_orig(VALUE x, int base, char* pt https://github.com/ruby/ruby/blob/trunk/bignum.c#L1088
 
 static long
 big2str_karatsuba(VALUE x, int base, char* ptr,
-		  long n1, long len, long hbase, int trim)
+		  long n1, long len, long hbase, int hbase_numdigits, int trim)
 {
     long lh, ll, m1;
     VALUE b, q, r;
@@ -1102,7 +1102,7 @@ big2str_karatsuba(VALUE x, int base, cha https://github.com/ruby/ruby/blob/trunk/bignum.c#L1102
     }
 
     if (n1 <= KARATSUBA_DIGITS) {
-	return big2str_orig(x, base, ptr, len, hbase, trim);
+	return big2str_orig(x, base, ptr, len, hbase, hbase_numdigits, trim);
     }
 
     b = power_cache_get_power(base, n1, &m1);
@@ -1110,10 +1110,10 @@ big2str_karatsuba(VALUE x, int base, cha https://github.com/ruby/ruby/blob/trunk/bignum.c#L1110
     rb_obj_hide(q);
     rb_obj_hide(r);
     lh = big2str_karatsuba(q, base, ptr, (len - m1)/2,
-			   len - m1, hbase, trim);
+			   len - m1, hbase, hbase_numdigits, trim);
     rb_big_resize(q, 0);
     ll = big2str_karatsuba(r, base, ptr + lh, m1/2,
-			   m1, hbase, !lh && trim);
+			   m1, hbase, hbase_numdigits, !lh && trim);
     rb_big_resize(r, 0);
 
     return lh + ll;
@@ -1125,6 +1125,7 @@ rb_big2str0(VALUE x, int base, int trim) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1125
     int off;
     VALUE ss, xx;
     long n1, n2, len, hbase;
+    int hbase_numdigits;
     char* ptr;
 
     if (FIXNUM_P(x)) {
@@ -1144,18 +1145,20 @@ rb_big2str0(VALUE x, int base, int trim) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1145
     ptr[0] = RBIGNUM_SIGN(x) ? '+' : '-';
 
     hbase = base*base;
+    hbase_numdigits = 2;
 #if SIZEOF_BDIGITS > 2
     hbase *= hbase;
+    hbase_numdigits *= 2;
 #endif
     off = !(trim && RBIGNUM_SIGN(x)); /* erase plus sign if trim */
     xx = rb_big_clone(x);
     RBIGNUM_SET_SIGN(xx, 1);
     if (n1 <= KARATSUBA_DIGITS) {
-	len = off + big2str_orig(xx, base, ptr + off, n2, hbase, trim);
+	len = off + big2str_orig(xx, base, ptr + off, n2, hbase, hbase_numdigits, trim);
     }
     else {
 	len = off + big2str_karatsuba(xx, base, ptr + off, n1,
-				      n2, hbase, trim);
+				      n2, hbase, hbase_numdigits, trim);
     }
     rb_big_resize(xx, 0);
 

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

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