aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-29 13:33:40 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-06-29 13:33:40 +0000
commit69f1a3351fe731e8d92c2f1c7f8507c08fb7e59b (patch)
tree81689a9538af14f464a71a77a7e7c3ad8b2bbf48 /bignum.c
parentc6cb7416d21e348a44cf17dad0c603d1c6a23a8b (diff)
downloadruby-69f1a3351fe731e8d92c2f1c7f8507c08fb7e59b.tar.gz
* bignum.c (bary_2comp): Simplified.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@41694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c15
1 files changed, 7 insertions, 8 deletions
diff --git a/bignum.c b/bignum.c
index aab97fae42..583d324560 100644
--- a/bignum.c
+++ b/bignum.c
@@ -271,16 +271,15 @@ static int
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 */