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

ruby-changes:29536

From: akr <ko1@a...>
Date: Mon, 24 Jun 2013 01:05:26 +0900 (JST)
Subject: [ruby-changes:29536] akr:r41588 (trunk): * bignum.c (BIGUP): Use LSHIFTX and avoid cast to consider the type

akr	2013-06-24 01:05:15 +0900 (Mon, 24 Jun 2013)

  New Revision: 41588

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

  Log:
    * bignum.c (BIGUP): Use LSHIFTX and avoid cast to consider the type
      of x is bigger than BDIGIT_DBL.
      (big2ulong): Use unsigned long to store the result.
      (big2ull): Use unsigned LONG_LONG to store the result.
      (bigand_int): Use long for num to avoid data loss.
      (bigor_int): Ditto.
      (bigxor_int): Ditto.

  Modified files:
    trunk/ChangeLog
    trunk/bignum.c

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 41587)
+++ ChangeLog	(revision 41588)
@@ -1,3 +1,13 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Mon Jun 24 00:59:35 2013  Tanaka Akira  <akr@f...>
+
+	* bignum.c (BIGUP): Use LSHIFTX and avoid cast to consider the type
+	  of x is bigger than BDIGIT_DBL.
+	  (big2ulong): Use unsigned long to store the result.
+	  (big2ull): Use unsigned LONG_LONG to store the result.
+	  (bigand_int): Use long for num to avoid data loss.
+	  (bigor_int): Ditto.
+	  (bigxor_int): Ditto.
+
 Sun Jun 23 23:05:58 2013  Tanaka Akira  <akr@f...>
 
 	* include/ruby/defines.h (BDIGIT): Define it only if it is not defined
Index: bignum.c
===================================================================
--- bignum.c	(revision 41587)
+++ bignum.c	(revision 41588)
@@ -55,7 +55,7 @@ static VALUE big_three = Qnil; https://github.com/ruby/ruby/blob/trunk/bignum.c#L55
 #if defined(HAVE_LONG_LONG) && SIZEOF_LONG_LONG >= SIZEOF_BDIGITS
 # define DIGSPERLL (SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
 #endif
-#define BIGUP(x) ((BDIGIT_DBL)(x) << BITSPERDIG)
+#define BIGUP(x) LSHIFTX(((x) + (BDIGIT_DBL)0), BITSPERDIG)
 #define BIGDN(x) RSHIFT((x),BITSPERDIG)
 #define BIGLO(x) ((BDIGIT)((x) & BDIGMAX))
 #define BDIGMAX ((BDIGIT)(BIGRAD-1))
@@ -2409,7 +2409,7 @@ static unsigned long https://github.com/ruby/ruby/blob/trunk/bignum.c#L2409
 big2ulong(VALUE x, const char *type, int check)
 {
     long len = RBIGNUM_LEN(x);
-    BDIGIT_DBL num;
+    unsigned long num;
     BDIGIT *ds;
 
     if (BIGSIZE(x) > sizeof(long)) {
@@ -2423,7 +2423,7 @@ big2ulong(VALUE x, const char *type, int https://github.com/ruby/ruby/blob/trunk/bignum.c#L2423
 	num = BIGUP(num);
 	num += ds[len];
     }
-    return (unsigned long)num;
+    return num;
 }
 
 VALUE
@@ -2477,7 +2477,7 @@ static unsigned LONG_LONG https://github.com/ruby/ruby/blob/trunk/bignum.c#L2477
 big2ull(VALUE x, const char *type)
 {
     long len = RBIGNUM_LEN(x);
-    BDIGIT_DBL num;
+    unsigned LONG_LONG num;
     BDIGIT *ds;
 
     if (len > SIZEOF_LONG_LONG/SIZEOF_BDIGITS)
@@ -4569,7 +4569,7 @@ bigand_int(VALUE x, long y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4569
     zds[0] = xds[0] & y;
 #else
     {
-	BDIGIT_DBL num = y;
+	long num = y;
 
 	for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) {
 	    zds[i] = xds[i] & BIGLO(num);
@@ -4665,7 +4665,7 @@ bigor_int(VALUE x, long y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4665
     zds[0] = xds[0] | y;
 #else
     {
-	BDIGIT_DBL num = y;
+	long num = y;
 
 	for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) {
 	    zds[i] = xds[i] | BIGLO(num);
@@ -4761,7 +4761,7 @@ bigxor_int(VALUE x, long y) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4761
     zds[0] = xds[0] ^ y;
 #else
     {
-	BDIGIT_DBL num = y;
+	long num = y;
 
 	for (i=0; i<bdigit_roomof(SIZEOF_LONG); i++) {
 	    zds[i] = xds[i] ^ BIGLO(num);

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

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