summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-02-15 04:43:58 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2002-02-15 04:43:58 +0000
commit289430e8eceaa8a9f541e455f0ffb8186ba06acd (patch)
treeb20c78bfd137e6f2760e957348d6c7e926a36a7a /bignum.c
parent9bd2c2681f9de7d68cae20116ad790b85e655667 (diff)
* bignum.c (rb_big_rshift): should properly convert the nagative
value to 2's compliment. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2072 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c8
1 files changed, 8 insertions, 0 deletions
diff --git a/bignum.c b/bignum.c
index d59969cdd9..90a4c77012 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1468,12 +1468,17 @@ rb_big_rshift(x, y)
long j;
if (shift < 0) return rb_big_lshift(x, INT2FIX(-shift));
+
if (s1 > RBIGNUM(x)->len) {
if (RBIGNUM(x)->sign)
return INT2FIX(0);
else
return INT2FIX(-1);
}
+ if (!RBIGNUM(x)->sign) {
+ x = rb_big_clone(x);
+ rb_big_2comp(x);
+ }
xds = BDIGITS(x);
i = RBIGNUM(x)->len; j = i - s1;
z = bignew(j, RBIGNUM(x)->sign);
@@ -1483,6 +1488,9 @@ rb_big_rshift(x, y)
zds[j] = BIGLO(num);
num = BIGUP(xds[i]);
}
+ if (!RBIGNUM(x)->sign) {
+ rb_big_2comp(z);
+ }
return bignorm(z);
}