aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-22 21:52:30 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-22 21:52:30 +0100
commita9f59db809d45847779b9c631d663a25b6115d7d (patch)
tree5d1492f5874e9901c38a57270681f35c2c1c854a /miscutils
parent2ea8ddf8c245dd160eacf35409572c28345506f7 (diff)
downloadbusybox-a9f59db809d45847779b9c631d663a25b6115d7d.tar.gz
bc: avoid having to twiddle b->neg in zbc_num_p()
function old new delta zbc_num_ulong_abs - 70 +70 zbc_num_p 424 413 -11 zbc_num_ulong 81 21 -60 ------------------------------------------------------------------------------ (add/remove: 1/0 grow/shrink: 0/2 up/down: 70/-71) Total: -1 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c18
1 files changed, 11 insertions, 7 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index d7595ce8e..ae5105b01 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1439,13 +1439,11 @@ static void bc_num_copy(BcNum *d, BcNum *s)
}
}
-static BC_STATUS zbc_num_ulong(BcNum *n, unsigned long *result_p)
+static BC_STATUS zbc_num_ulong_abs(BcNum *n, unsigned long *result_p)
{
size_t i;
unsigned long result;
- if (n->neg) RETURN_STATUS(bc_error("negative number"));
-
result = 0;
i = n->len;
while (i > n->rdx) {
@@ -1462,6 +1460,14 @@ static BC_STATUS zbc_num_ulong(BcNum *n, unsigned long *result_p)
RETURN_STATUS(BC_STATUS_SUCCESS);
}
+#define zbc_num_ulong_abs(...) (zbc_num_ulong_abs(__VA_ARGS__) COMMA_SUCCESS)
+
+static BC_STATUS zbc_num_ulong(BcNum *n, unsigned long *result_p)
+{
+ if (n->neg) RETURN_STATUS(bc_error("negative number"));
+
+ RETURN_STATUS(zbc_num_ulong_abs(n, result_p));
+}
#define zbc_num_ulong(...) (zbc_num_ulong(__VA_ARGS__) COMMA_SUCCESS)
#if ULONG_MAX == 0xffffffffUL // 10 digits: 4294967295
@@ -2109,9 +2115,7 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size
}
neg = b->neg;
- b->neg = false;
- s = zbc_num_ulong(b, &pow);
- b->neg = neg;
+ s = zbc_num_ulong_abs(b, &pow);
if (s) RETURN_STATUS(s);
// b is not used beyond this point
@@ -6150,7 +6154,6 @@ static BC_STATUS zdc_program_asciify(void)
char *str;
char c;
size_t idx;
- unsigned long val;
if (!STACK_HAS_MORE_THAN(&G.prog.results, 0))
RETURN_STATUS(bc_error_stack_has_too_few_elements());
@@ -6160,6 +6163,7 @@ static BC_STATUS zdc_program_asciify(void)
if (s) RETURN_STATUS(s);
if (BC_PROG_NUM(r, num)) {
+ unsigned long val;
BcNum strmb;
BcDig strmb_digs[ULONG_NUM_BUFSIZE];