ruby-changes:29845
From: akr <ko1@a...>
Date: Wed, 10 Jul 2013 22:06:45 +0900 (JST)
Subject: [ruby-changes:29845] akr:r41897 (trunk): * bignum.c (bary_2comp): Don't use bary_plus_one.
akr 2013-07-10 22:06:33 +0900 (Wed, 10 Jul 2013) New Revision: 41897 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41897 Log: * bignum.c (bary_2comp): Don't use bary_plus_one. (bary_add_one): Replaced by the implementation of bary_plus_one. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41896) +++ ChangeLog (revision 41897) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Wed Jul 10 22:03:27 2013 Tanaka Akira <akr@f...> + + * 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@r...> * bignum.c (sizeof_bdigit_dbl): check sizeof(BDIGIT_DBL). Index: bignum.c =================================================================== --- bignum.c (revision 41896) +++ bignum.c (revision 41897) @@ -458,23 +458,24 @@ bary_neg(BDIGIT *ds, size_t n) https://github.com/ruby/ruby/blob/trunk/bignum.c#L458 } static int -bary_plus_one(BDIGIT *ds, size_t n) +bary_2comp(BDIGIT *ds, size_t n) { size_t i; + i = 0; for (i = 0; i < n; i++) { - ds[i] = BIGLO(ds[i]+1); - if (ds[i] != 0) - return 0; + if (ds[i] != 0) { + goto non_zero; + } } return 1; -} -static int -bary_2comp(BDIGIT *ds, size_t n) -{ - if (!n) return 1; - bary_neg(ds, n); - return bary_plus_one(ds, n); + non_zero: + ds[i] = BIGLO(~ds[i] + 1); + i++; + for (; i < n; i++) { + ds[i] = BIGLO(~ds[i]); + } + return 0; } static void @@ -1422,9 +1423,15 @@ bary_add(BDIGIT *zds, size_t zn, BDIGIT https://github.com/ruby/ruby/blob/trunk/bignum.c#L1423 } 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 @@ -4028,14 +4035,14 @@ rb_big_neg(VALUE x) https://github.com/ruby/ruby/blob/trunk/bignum.c#L4035 if (!n) return INT2FIX(-1); if (RBIGNUM_POSITIVE_P(z)) { - if (bary_plus_one(ds, n)) { + if (bary_add_one(ds, n)) { big_extend_carry(z); } RBIGNUM_SET_NEGATIVE_SIGN(z); } else { bary_neg(ds, n); - if (bary_plus_one(ds, n)) + if (bary_add_one(ds, n)) return INT2FIX(-1); bary_neg(ds, n); RBIGNUM_SET_POSITIVE_SIGN(z); -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/