From a2c9020808417572521c711cf4ad9a3c7b556575 Mon Sep 17 00:00:00 2001 From: matz Date: Fri, 4 Oct 2002 17:54:29 +0000 Subject: * 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 --- bignum.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 537852d959..4db4bdb6a6 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; -- cgit v1.2.3