summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 02:59:30 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2018-11-16 02:59:30 +0000
commitca149140393097a4e82ddd9081bf0943cd50e946 (patch)
treecf6e9f9f0a22f1173f875fc957e6de974d3e0bc9 /bignum.c
parent6732423b5eb7191e81a23fe929926d50e0e4b39f (diff)
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. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65753 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index 766677a7ab..209b03e3e2 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1445,7 +1445,9 @@ bary_add_one(BDIGIT *ds, size_t n)
{
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)
}
}
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;
}
}