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

ruby-changes:29566

From: akr <ko1@a...>
Date: Tue, 25 Jun 2013 19:05:27 +0900 (JST)
Subject: [ruby-changes:29566] akr:r41618 (trunk): * bignum.c (big2ulong): Add a cast.

akr	2013-06-25 19:04:37 +0900 (Tue, 25 Jun 2013)

  New Revision: 41618

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

  Log:
    * bignum.c (big2ulong): Add a cast.
      (big2ull): Add a specialized code for SIZEOF_LONG_LONG <=
      SIZEOF_BDIGITS.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41617)
+++ ChangeLog	(revision 41618)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Tue Jun 25 19:03:00 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (big2ulong): Add a cast.
+	  (big2ull): Add a specialized code for SIZEOF_LONG_LONG <=
+	  SIZEOF_BDIGITS.
+
 Tue Jun 25 12:42:57 2013  Tanaka Akira  <akr@f...>
 
 	* bignum.c (integer_unpack_single_bdigit): Use "1 + ~u" instead of
Index: bignum.c
===================================================================
--- bignum.c	(revision 41617)
+++ bignum.c	(revision 41618)
@@ -2423,7 +2423,7 @@ big2ulong(VALUE x, const char *type, int https://github.com/ruby/ruby/blob/trunk/bignum.c#L2423
     }
     ds = BDIGITS(x);
 #if SIZEOF_LONG <= SIZEOF_BDIGITS
-    num = ds[0];
+    num = (unsigned long)ds[0];
 #else
     num = 0;
     while (len--) {
@@ -2486,16 +2486,21 @@ big2ull(VALUE x, const char *type) https://github.com/ruby/ruby/blob/trunk/bignum.c#L2486
 {
     long len = RBIGNUM_LEN(x);
     unsigned LONG_LONG num;
-    BDIGIT *ds;
+    BDIGIT *ds = BDIGITS(x);
 
-    if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
+    if (len == 0)
+        return 0;
+    if (BIGSIZE(x) > SIZEOF_LONG_LONG)
 	rb_raise(rb_eRangeError, "bignum too big to convert into `%s'", type);
-    ds = BDIGITS(x);
+#if SIZEOF_LONG_LONG <= SIZEOF_BDIGITS
+    num = (unsigned LONG_LONG)ds[0];
+#else
     num = 0;
     while (len--) {
 	num = BIGUP(num);
 	num += ds[len];
     }
+#endif
     return num;
 }
 

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

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