mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* bignum.c: forget to check in DIGSPERLONGLONG.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@2066 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
99facfbdf8
commit
6d75d13809
1 changed files with 18 additions and 2 deletions
20
bignum.c
20
bignum.c
|
@ -187,6 +187,8 @@ rb_int2inum(n)
|
||||||
|
|
||||||
#ifdef HAVE_LONG_LONG
|
#ifdef HAVE_LONG_LONG
|
||||||
|
|
||||||
|
#define DIGSPERLONGLONG ((unsigned int)(sizeof(LONG_LONG)/sizeof(BDIGIT)))
|
||||||
|
|
||||||
void
|
void
|
||||||
rb_quad_pack(buf, val)
|
rb_quad_pack(buf, val)
|
||||||
char *buf;
|
char *buf;
|
||||||
|
@ -267,13 +269,21 @@ rb_quad_pack(buf, val)
|
||||||
memset(buf, 0, QUAD_SIZE);
|
memset(buf, 0, QUAD_SIZE);
|
||||||
val = rb_to_int(val);
|
val = rb_to_int(val);
|
||||||
if (FIXNUM_P(val)) {
|
if (FIXNUM_P(val)) {
|
||||||
val = rb_uint2big(FIX2LONG(val));
|
val = rb_int2big(FIX2LONG(val));
|
||||||
}
|
}
|
||||||
len = RBIGNUM(val)->len * sizeof(BDIGIT);
|
len = RBIGNUM(val)->len * sizeof(BDIGIT);
|
||||||
if (len > QUAD_SIZE) len = QUAD_SIZE;
|
if (len > QUAD_SIZE) len = QUAD_SIZE;
|
||||||
memcpy(buf, (char*)BDIGITS(val), len);
|
memcpy(buf, (char*)BDIGITS(val), len);
|
||||||
|
if (!RBIGNUM(val)->sign) {
|
||||||
|
len = QUAD_SIZE;
|
||||||
|
while (len--) {
|
||||||
|
*buf = ~*buf++;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#define BNEG(b) (RSHIFT(((BDIGIT*)b)[QUAD_SIZE/sizeof(BDIGIT)-1],BITSPERDIG-1) != 0)
|
||||||
|
|
||||||
VALUE
|
VALUE
|
||||||
rb_quad_unpack(buf, sign)
|
rb_quad_unpack(buf, sign)
|
||||||
const char *buf;
|
const char *buf;
|
||||||
|
@ -282,8 +292,14 @@ rb_quad_unpack(buf, sign)
|
||||||
VALUE big = bignew(QUAD_SIZE/sizeof(BDIGIT), 1);
|
VALUE big = bignew(QUAD_SIZE/sizeof(BDIGIT), 1);
|
||||||
|
|
||||||
memcpy((char*)BDIGITS(big), buf, QUAD_SIZE);
|
memcpy((char*)BDIGITS(big), buf, QUAD_SIZE);
|
||||||
if (sign && (buf[7] & 0x80)) {
|
if (sign && BNEG(buf)) {
|
||||||
|
long len = QUAD_SIZE;
|
||||||
|
char *tmp = (char*)BDIGITS(big);
|
||||||
|
|
||||||
RBIGNUM(big)->sign = 0;
|
RBIGNUM(big)->sign = 0;
|
||||||
|
while (len--) {
|
||||||
|
*tmp = ~*tmp++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return bignorm(big);
|
return bignorm(big);
|
||||||
|
|
Loading…
Reference in a new issue