1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* 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
This commit is contained in:
matz 2002-02-15 04:43:58 +00:00
parent 9bd2c2681f
commit 289430e8ec
4 changed files with 26 additions and 1 deletions

View file

@ -1,3 +1,8 @@
Fri Feb 15 13:36:58 2002 Yukihiro Matsumoto <matz@ruby-lang.org>
* bignum.c (rb_big_rshift): should properly convert the nagative
value to 2's compliment.
Thu Feb 14 17:38:35 2002 Nobuyoshi Nakada <nobu.nakada@nifty.ne.jp>
* parse.y: avoid SEGV at OP_ASIGN to pseudo variable.

View file

@ -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);
}

1
gc.c
View file

@ -258,7 +258,6 @@ typedef struct RVALUE {
struct RVarmap varmap;
struct SCOPE scope;
} as;
int type;
} RVALUE;
static RVALUE *freelist = 0;

View file

@ -809,6 +809,19 @@ b = 14269972710765292560
test_ok(a % b == 0)
test_ok(-a % b == 0)
def shift_test(a)
b = a / (2 ** 32)
c = a >> 32
test_ok(b == c)
b = a * (2 ** 32)
c = a << 32
test_ok(b == c)
end
shift_test(-4518325415524767873)
shift_test(-0xfffffffffffffffff)
test_check "string & char"
test_ok("abcd" == "abcd")