aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-18 00:39:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-18 03:30:23 +0100
commit4113e1f2cd2f45a95bcb0920bf2e3ee75b906281 (patch)
treeaf0914f73ee6af0d10fe6f4b8fb509905b1678d1
parent57734c926bbfe69d1c3bb6096fbdf428628ed838 (diff)
downloadbusybox-w32-4113e1f2cd2f45a95bcb0920bf2e3ee75b906281.tar.gz
busybox-w32-4113e1f2cd2f45a95bcb0920bf2e3ee75b906281.tar.bz2
busybox-w32-4113e1f2cd2f45a95bcb0920bf2e3ee75b906281.zip
bc: rewrite bc_num_compare() to be readable
function old new delta bc_num_compare 59 51 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c18
1 files changed, 14 insertions, 4 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index e5ad0ed86..eaab6cee6 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1475,10 +1475,20 @@ static void bc_num_subArrays(BcDig *restrict a, BcDig *restrict b,
1475 1475
1476static ssize_t bc_num_compare(BcDig *restrict a, BcDig *restrict b, size_t len) 1476static ssize_t bc_num_compare(BcDig *restrict a, BcDig *restrict b, size_t len)
1477{ 1477{
1478 size_t i; 1478 size_t i = len;
1479 int c = 0; 1479 for (;;) {
1480 for (i = len - 1; i < len && !(c = a[i] - b[i]); --i); 1480 int c;
1481 return BC_NUM_NEG(i + 1, c < 0); 1481 if (i == 0)
1482 return 0;
1483 i--;
1484 c = a[i] - b[i];
1485 if (c != 0) {
1486 i++;
1487 if (c < 0)
1488 return -i;
1489 return i;
1490 }
1491 }
1482} 1492}
1483 1493
1484static ssize_t bc_num_cmp(BcNum *a, BcNum *b) 1494static ssize_t bc_num_cmp(BcNum *a, BcNum *b)