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

ruby-changes:53537

From: shyouhei <ko1@a...>
Date: Fri, 16 Nov 2018 11:59:34 +0900 (JST)
Subject: [ruby-changes:53537] shyouhei:r65753 (trunk): bignum.c: BDIGIT might or might not integer-promote

shyouhei	2018-11-16 11:59:30 +0900 (Fri, 16 Nov 2018)

  New Revision: 65753

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=65753

  Log:
    bignum.c: BDIGIT might or might not integer-promote
    
    BDIGIT can be unsigned int or unsigned short, depending on BDIGIT_DBL.
    Given that, unsigned int and unsigned short are different in how
    integer promotion works.  BOGLO assumes its argument is wider than
    BDIGIT, which is not always true.  We have to force that explicitly.

  Modified files:
    trunk/bignum.c
Index: bignum.c
===================================================================
--- bignum.c	(revision 65752)
+++ bignum.c	(revision 65753)
@@ -1445,7 +1445,9 @@ bary_add_one(BDIGIT *ds, size_t n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L1445
 {
     size_t i;
     for (i = 0; i < n; i++) {
-	ds[i] = BIGLO(ds[i]+1);
+        BDIGIT_DBL n = ds[i];
+        n += 1;
+        ds[i] = BIGLO(n);
         if (ds[i] != 0)
             return 0;
     }
@@ -5271,8 +5273,12 @@ big2dbl(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L5273
 		    }
 		}
 		if (carry) {
-		    dl &= BDIGMAX << bits;
-		    dl = BIGLO(dl + ((BDIGIT)1 << bits));
+                    BDIGIT mask = BDIGMAX;
+                    BDIGIT bit = 1;
+                    mask <<= bits;
+                    bit <<= bits;
+                    dl &= mask;
+                    dl |= bit;
 		    if (!dl) d += 1;
 		}
 	    }

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

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