* bignum.c (abs2twocomp_bang): Removed.
(abs2twocomp): Take n_ret argument to return actual length. (rb_big_and): Follow above change. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41681 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cd6912a595
commit
ef18728433
@ -1,3 +1,9 @@
|
|||||||
|
Thu Jun 27 23:58:13 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
|
* bignum.c (abs2twocomp_bang): Removed.
|
||||||
|
(abs2twocomp): Take n_ret argument to return actual length.
|
||||||
|
(rb_big_and): Follow above change.
|
||||||
|
|
||||||
Thu Jun 27 22:52:19 2013 Tanaka Akira <akr@fsij.org>
|
Thu Jun 27 22:52:19 2013 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* bignum.c (get2comp): Use bary_2comp.
|
* bignum.c (get2comp): Use bary_2comp.
|
||||||
|
47
bignum.c
47
bignum.c
@ -304,37 +304,24 @@ rb_big_2comp(VALUE x) /* get 2's complement */
|
|||||||
}
|
}
|
||||||
|
|
||||||
static BDIGIT
|
static BDIGIT
|
||||||
abs2twocomp_bang(VALUE x)
|
abs2twocomp(VALUE *xp, long *n_ret)
|
||||||
{
|
{
|
||||||
long numbdigits = RBIGNUM_LEN(x);
|
VALUE x = *xp;
|
||||||
long n;
|
long n = RBIGNUM_LEN(x);
|
||||||
BDIGIT *ds = BDIGITS(x);
|
BDIGIT *ds = BDIGITS(x);
|
||||||
BDIGIT hibits;
|
BDIGIT hibits = 0;
|
||||||
|
|
||||||
n = numbdigits;
|
|
||||||
|
|
||||||
while (0 < n && ds[n-1] == 0)
|
while (0 < n && ds[n-1] == 0)
|
||||||
n--;
|
n--;
|
||||||
|
|
||||||
if (n == 0 || RBIGNUM_POSITIVE_P(x))
|
if (n != 0 && RBIGNUM_NEGATIVE_P(x)) {
|
||||||
hibits = 0;
|
VALUE z = bignew_1(CLASS_OF(x), n, 0);
|
||||||
else {
|
MEMCPY(BDIGITS(z), ds, BDIGIT, n);
|
||||||
|
bary_2comp(BDIGITS(z), n);
|
||||||
hibits = BDIGMAX;
|
hibits = BDIGMAX;
|
||||||
bary_2comp(ds, numbdigits);
|
*xp = z;
|
||||||
}
|
|
||||||
|
|
||||||
return hibits;
|
|
||||||
}
|
|
||||||
|
|
||||||
static BDIGIT
|
|
||||||
abs2twocomp(VALUE *xp)
|
|
||||||
{
|
|
||||||
VALUE x = *xp;
|
|
||||||
BDIGIT hibits = 0;
|
|
||||||
if (RBIGNUM_NEGATIVE_P(x)) {
|
|
||||||
*xp = x = rb_big_clone(x);
|
|
||||||
hibits = abs2twocomp_bang(x);
|
|
||||||
}
|
}
|
||||||
|
*n_ret = n;
|
||||||
return hibits;
|
return hibits;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -4730,27 +4717,29 @@ rb_big_and(VALUE x, VALUE y)
|
|||||||
{
|
{
|
||||||
VALUE z;
|
VALUE z;
|
||||||
BDIGIT *ds1, *ds2, *zds;
|
BDIGIT *ds1, *ds2, *zds;
|
||||||
long i, l1, l2;
|
long i, xl, yl, l1, l2;
|
||||||
BDIGIT hibitsx, hibitsy;
|
BDIGIT hibitsx, hibitsy;
|
||||||
BDIGIT hibits1, hibits2;
|
BDIGIT hibits1, hibits2;
|
||||||
VALUE tmpv;
|
VALUE tmpv;
|
||||||
BDIGIT tmph;
|
BDIGIT tmph;
|
||||||
|
long tmpl;
|
||||||
|
|
||||||
if (!FIXNUM_P(y) && !RB_TYPE_P(y, T_BIGNUM)) {
|
if (!FIXNUM_P(y) && !RB_TYPE_P(y, T_BIGNUM)) {
|
||||||
return rb_num_coerce_bit(x, y, '&');
|
return rb_num_coerce_bit(x, y, '&');
|
||||||
}
|
}
|
||||||
|
|
||||||
hibitsx = abs2twocomp(&x);
|
hibitsx = abs2twocomp(&x, &xl);
|
||||||
if (FIXNUM_P(y)) {
|
if (FIXNUM_P(y)) {
|
||||||
return bigand_int(x, FIX2LONG(y));
|
return bigand_int(x, FIX2LONG(y));
|
||||||
}
|
}
|
||||||
hibitsy = abs2twocomp(&y);
|
hibitsy = abs2twocomp(&y, &yl);
|
||||||
if (RBIGNUM_LEN(x) > RBIGNUM_LEN(y)) {
|
if (xl > yl) {
|
||||||
tmpv = x; x = y; y = tmpv;
|
tmpv = x; x = y; y = tmpv;
|
||||||
|
tmpl = xl; xl = yl; yl = tmpl;
|
||||||
tmph = hibitsx; hibitsx = hibitsy; hibitsy = tmph;
|
tmph = hibitsx; hibitsx = hibitsy; hibitsy = tmph;
|
||||||
}
|
}
|
||||||
l1 = RBIGNUM_LEN(x);
|
l1 = xl;
|
||||||
l2 = RBIGNUM_LEN(y);
|
l2 = yl;
|
||||||
ds1 = BDIGITS(x);
|
ds1 = BDIGITS(x);
|
||||||
ds2 = BDIGITS(y);
|
ds2 = BDIGITS(y);
|
||||||
hibits1 = hibitsx;
|
hibits1 = hibitsx;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user