summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-04 17:54:29 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-10-04 17:54:29 +0000
commita2c9020808417572521c711cf4ad9a3c7b556575 (patch)
tree421344d18596a3c8c3d998e41fcf848ac54a5054 /bignum.c
parent1e3062ede1765f21c501068b3489c390c914e55f (diff)
* bignum.c (rb_big_rshift): num should be initialized by carry
bits if x is negative. * bignum.c (bigdivmod): len for bignum zero is 1, not 0. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2936 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c6
1 files changed, 5 insertions, 1 deletions
diff --git a/bignum.c b/bignum.c
index 537852d..4db4bdb 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1243,7 +1243,8 @@ bigdivmod(x, y, divp, modp)
VALUE mod;
bigdivrem(x, y, divp, &mod);
- if (RBIGNUM(x)->sign != RBIGNUM(y)->sign && RBIGNUM(mod)->len > 0) {
+ if (RBIGNUM(x)->sign != RBIGNUM(y)->sign &&
+ RBIGNUM(mod)->len > 0 && BDIGITS(mod)[0] != 0) {
if (divp) *divp = bigadd(*divp, rb_int2big(1), 0);
if (modp) *modp = bigadd(mod, y, 1);
}
@@ -1603,6 +1604,9 @@ rb_big_rshift(x, y)
xds = BDIGITS(x);
i = RBIGNUM(x)->len; j = i - s1;
z = bignew(j, RBIGNUM(x)->sign);
+ if (!RBIGNUM(x)->sign) {
+ num = ((BDIGIT_DBL)~0) << BITSPERDIG;
+ }
zds = BDIGITS(z);
while (i--, j--) {
num = (num | xds[i]) >> s2;