ruby-changes:29642
From: akr <ko1@a...>
Date: Sat, 29 Jun 2013 22:33:52 +0900 (JST)
Subject: [ruby-changes:29642] akr:r41694 (trunk): * bignum.c (bary_2comp): Simplified.
akr 2013-06-29 22:33:40 +0900 (Sat, 29 Jun 2013) New Revision: 41694 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=41694 Log: * bignum.c (bary_2comp): Simplified. Modified files: trunk/ChangeLog trunk/bignum.c Index: ChangeLog =================================================================== --- ChangeLog (revision 41693) +++ ChangeLog (revision 41694) @@ -1,3 +1,7 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sat Jun 29 22:31:59 2013 Tanaka Akira <akr@f...> + + * bignum.c (bary_2comp): Simplified. + Sat Jun 29 09:33:53 2013 Tanaka Akira <akr@f...> * bignum.c (bigor_int): Return -1 if y == -1. Index: bignum.c =================================================================== --- bignum.c (revision 41693) +++ bignum.c (revision 41694) @@ -271,16 +271,15 @@ static int https://github.com/ruby/ruby/blob/trunk/bignum.c#L271 bary_2comp(BDIGIT *ds, size_t n) { size_t i = n; - BDIGIT_DBL num; if (!n) return 1; while (i--) ds[i] = BIGLO(~ds[i]); - i = 0; num = 1; - do { - num += ds[i]; - ds[i++] = BIGLO(num); - num = BIGDN(num); - } while (i < n); - return num != 0; + i = 0; + for (i = 0; i < n; i++) { + ds[i] = BIGLO(ds[i]+1); + if (ds[i] != 0) + return 0; + } + return 1; } /* modify a bignum by 2's complement */ -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/