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

ruby-changes:29378

From: akr <ko1@a...>
Date: Wed, 19 Jun 2013 21:19:21 +0900 (JST)
Subject: [ruby-changes:29378] akr:r41430 (trunk): * bignum.c (rb_uint2big): Consider environments BDIGIT is bigger than

akr	2013-06-19 21:19:10 +0900 (Wed, 19 Jun 2013)

  New Revision: 41430

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

  Log:
    * bignum.c (rb_uint2big): Consider environments BDIGIT is bigger than
      long.
      (big2ulong): Ditto.
      (rb_big_aref): Ditto.
      (rb_big_pack): Just call rb_integer_pack.
      (rb_big_unpack): Just call rb_integer_unpack.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41429)
+++ ChangeLog	(revision 41430)
@@ -1,3 +1,12 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Wed Jun 19 21:02:13 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (rb_uint2big): Consider environments BDIGIT is bigger than
+	  long.
+	  (big2ulong): Ditto.
+	  (rb_big_aref): Ditto.
+	  (rb_big_pack): Just call rb_integer_pack.
+	  (rb_big_unpack): Just call rb_integer_unpack.
+
 Wed Jun 19 20:51:21 2013  Kazuhiro NISHIYAMA  <zn@m...>
 
 	* gc.c (gc_stress_get): GC.stress can be Fixnum.
Index: bignum.c
===================================================================
--- bignum.c	(revision 41429)
+++ bignum.c	(revision 41430)
@@ -332,19 +332,25 @@ rb_big_norm(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L332
 VALUE
 rb_uint2big(VALUE n)
 {
-    BDIGIT_DBL num = n;
     long i = 0;
     BDIGIT *digits;
     VALUE big;
 
-    big = bignew(DIGSPERLONG, 1);
+#if SIZEOF_BDIGITS >= SIZEOF_VALUE
+    big = bignew(1, 1);
     digits = BDIGITS(big);
-    while (i < DIGSPERLONG) {
+    digits[0] = n;
+#else
+    BDIGIT_DBL num = n;
+    big = bignew(bdigit_roomof(SIZEOF_VALUE), 1);
+    digits = BDIGITS(big);
+    while (i < bdigit_roomof(SIZEOF_VALUE)) {
 	digits[i++] = BIGLO(num);
 	num = BIGDN(num);
     }
+#endif
 
-    i = DIGSPERLONG;
+    i = bdigit_roomof(SIZEOF_VALUE);;
     while (--i && !digits[i]) ;
     RBIGNUM_SET_LEN(big, i+1);
     return big;
@@ -385,6 +391,7 @@ rb_int2inum(SIGNED_VALUE n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L391
     return rb_int2big(n);
 }
 
+#if 0
 #if SIZEOF_LONG % SIZEOF_BDIGITS != 0
 # error unexpected SIZEOF_LONG : SIZEOF_BDIGITS ratio
 #endif
@@ -410,6 +417,7 @@ rb_int2inum(SIGNED_VALUE n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L417
  * If given size of buf (num_longs) is not enough to represent val,
  * higher words (including a sign bit) are ignored.
  */
+
 void
 rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
 {
@@ -493,6 +501,23 @@ rb_big_unpack(unsigned long *buf, long n https://github.com/ruby/ruby/blob/trunk/bignum.c#L501
         return bignorm(big);
     }
 }
+#endif
+
+void
+rb_big_pack(VALUE val, unsigned long *buf, long num_longs)
+{
+    rb_integer_pack(val, buf, num_longs, sizeof(long), 0,
+            INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER|
+            INTEGER_PACK_2COMP);
+}
+
+VALUE
+rb_big_unpack(unsigned long *buf, long num_longs)
+{
+    return rb_integer_unpack(buf, num_longs, sizeof(long), 0,
+            INTEGER_PACK_LSWORD_FIRST|INTEGER_PACK_NATIVE_BYTE_ORDER|
+            INTEGER_PACK_2COMP);
+}
 
 /* number of bytes of abs(val). additionaly number of leading zeros can be returned. */
 
@@ -2228,10 +2253,10 @@ big2ulong(VALUE x, const char *type, int https://github.com/ruby/ruby/blob/trunk/bignum.c#L2253
     BDIGIT_DBL num;
     BDIGIT *ds;
 
-    if (len > DIGSPERLONG) {
+    if (rb_absint_size(x, NULL) > sizeof(long)) {
 	if (check)
 	    rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
-	len = DIGSPERLONG;
+	len = sizeof(long)/SIZEOF_BDIGITS;
     }
     ds = BDIGITS(x);
     num = 0;
@@ -2239,7 +2264,7 @@ big2ulong(VALUE x, const char *type, int https://github.com/ruby/ruby/blob/trunk/bignum.c#L2264
 	num = BIGUP(num);
 	num += ds[len];
     }
-    return (VALUE)num;
+    return (VALUE)(unsigned long)num;
 }
 
 VALUE
@@ -4861,7 +4886,7 @@ rb_big_aref(VALUE x, VALUE y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4886
 	if (!RBIGNUM_SIGN(y))
 	    return INT2FIX(0);
 	bigtrunc(y);
-	if (RBIGNUM_LEN(y) > DIGSPERLONG) {
+	if (rb_absint_size(y, NULL) > sizeof(long)) {
 	  out_of_range:
 	    return RBIGNUM_SIGN(x) ? INT2FIX(0) : INT2FIX(1);
 	}

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

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