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

* bignum.c (bary_2comp): Don't use bary_plus_one.

(bary_add_one): Replaced by the implementation of bary_plus_one.



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41897 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2013-07-10 13:06:33 +00:00
parent c37e6ab28d
commit 55e60d05dc
2 changed files with 31 additions and 19 deletions

View file

@ -1,3 +1,8 @@
Wed Jul 10 22:03:27 2013 Tanaka Akira <akr@fsij.org>
* bignum.c (bary_2comp): Don't use bary_plus_one.
(bary_add_one): Replaced by the implementation of bary_plus_one.
Wed Jul 10 20:48:22 2013 Nobuyoshi Nakada <nobu@ruby-lang.org> Wed Jul 10 20:48:22 2013 Nobuyoshi Nakada <nobu@ruby-lang.org>
* bignum.c (sizeof_bdigit_dbl): check sizeof(BDIGIT_DBL). * bignum.c (sizeof_bdigit_dbl): check sizeof(BDIGIT_DBL).

View file

@ -457,24 +457,25 @@ bary_neg(BDIGIT *ds, size_t n)
ds[n] = BIGLO(~ds[n]); ds[n] = BIGLO(~ds[n]);
} }
static int
bary_plus_one(BDIGIT *ds, size_t n)
{
size_t i;
for (i = 0; i < n; i++) {
ds[i] = BIGLO(ds[i]+1);
if (ds[i] != 0)
return 0;
}
return 1;
}
static int static int
bary_2comp(BDIGIT *ds, size_t n) bary_2comp(BDIGIT *ds, size_t n)
{ {
if (!n) return 1; size_t i;
bary_neg(ds, n); i = 0;
return bary_plus_one(ds, n); for (i = 0; i < n; i++) {
if (ds[i] != 0) {
goto non_zero;
}
}
return 1;
non_zero:
ds[i] = BIGLO(~ds[i] + 1);
i++;
for (; i < n; i++) {
ds[i] = BIGLO(~ds[i]);
}
return 0;
} }
static void static void
@ -1422,9 +1423,15 @@ bary_add(BDIGIT *zds, size_t zn, BDIGIT *xds, size_t xn, BDIGIT *yds, size_t yn)
} }
static int static int
bary_add_one(BDIGIT *zds, size_t zn) bary_add_one(BDIGIT *ds, size_t n)
{ {
return bary_addc(zds, zn, NULL, 0, zds, zn, 1); size_t i;
for (i = 0; i < n; i++) {
ds[i] = BIGLO(ds[i]+1);
if (ds[i] != 0)
return 0;
}
return 1;
} }
static void static void
@ -4028,14 +4035,14 @@ rb_big_neg(VALUE x)
if (!n) return INT2FIX(-1); if (!n) return INT2FIX(-1);
if (RBIGNUM_POSITIVE_P(z)) { if (RBIGNUM_POSITIVE_P(z)) {
if (bary_plus_one(ds, n)) { if (bary_add_one(ds, n)) {
big_extend_carry(z); big_extend_carry(z);
} }
RBIGNUM_SET_NEGATIVE_SIGN(z); RBIGNUM_SET_NEGATIVE_SIGN(z);
} }
else { else {
bary_neg(ds, n); bary_neg(ds, n);
if (bary_plus_one(ds, n)) if (bary_add_one(ds, n))
return INT2FIX(-1); return INT2FIX(-1);
bary_neg(ds, n); bary_neg(ds, n);
RBIGNUM_SET_POSITIVE_SIGN(z); RBIGNUM_SET_POSITIVE_SIGN(z);