aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-29 16:23:34 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-29 16:23:34 +0100
commit8ab209f00ebfc9afeeed70bc950817a2567e7389 (patch)
tree30b5b3bea0812de5bab45db7c1837bc54ef6b725
parent374d2c47ec956b43ced2879cd8305db616625103 (diff)
downloadbusybox-w32-8ab209f00ebfc9afeeed70bc950817a2567e7389.tar.gz
busybox-w32-8ab209f00ebfc9afeeed70bc950817a2567e7389.tar.bz2
busybox-w32-8ab209f00ebfc9afeeed70bc950817a2567e7389.zip
bc: simplify representation of 0.5 in sqrt()
function old new delta zxc_program_exec 4012 4149 +137 zdc_program_printStream 144 - -144 ------------------------------------------------------------------------------ (add/remove: 0/1 grow/shrink: 1/0 up/down: 137/-144) Total: -7 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c25
1 files changed, 15 insertions, 10 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 500d97123..081e48ba8 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2157,6 +2157,7 @@ static BC_STATUS zbc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale)
2157{ 2157{
2158 BcStatus s; 2158 BcStatus s;
2159 BcNum num1, num2, half, f, fprime, *x0, *x1, *temp; 2159 BcNum num1, num2, half, f, fprime, *x0, *x1, *temp;
2160 BcDig half_digs[1];
2160 size_t pow, len, digs, digs1, resrdx, req, times = 0; 2161 size_t pow, len, digs, digs1, resrdx, req, times = 0;
2161 ssize_t cmp = 1, cmp1 = SSIZE_MAX, cmp2 = SSIZE_MAX; 2162 ssize_t cmp = 1, cmp1 = SSIZE_MAX, cmp2 = SSIZE_MAX;
2162 2163
@@ -2181,10 +2182,11 @@ static BC_STATUS zbc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale)
2181 2182
2182 bc_num_init(&num1, len); 2183 bc_num_init(&num1, len);
2183 bc_num_init(&num2, len); 2184 bc_num_init(&num2, len);
2184 bc_num_init_DEF_SIZE(&half);
2185 2185
2186 half.cap = ARRAY_SIZE(half_digs);
2187 half.num = half_digs;
2186 bc_num_one(&half); 2188 bc_num_one(&half);
2187 half.num[0] = 5; 2189 half_digs[0] = 5;
2188 half.rdx = 1; 2190 half.rdx = 1;
2189 2191
2190 bc_num_init(&f, len); 2192 bc_num_init(&f, len);
@@ -2247,7 +2249,6 @@ static BC_STATUS zbc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale)
2247 err: 2249 err:
2248 bc_num_free(&fprime); 2250 bc_num_free(&fprime);
2249 bc_num_free(&f); 2251 bc_num_free(&f);
2250 bc_num_free(&half);
2251 bc_num_free(&num2); 2252 bc_num_free(&num2);
2252 bc_num_free(&num1); 2253 bc_num_free(&num1);
2253 RETURN_STATUS(s); 2254 RETURN_STATUS(s);
@@ -2285,7 +2286,7 @@ static BC_STATUS zdc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d)
2285{ 2286{
2286 BcStatus s; 2287 BcStatus s;
2287 BcNum base, exp, two, temp; 2288 BcNum base, exp, two, temp;
2288 BcDig two_digs[2]; 2289 BcDig two_digs[1];
2289 2290
2290 if (c->len == 0) 2291 if (c->len == 0)
2291 RETURN_STATUS(bc_error("divide by zero")); 2292 RETURN_STATUS(bc_error("divide by zero"));
@@ -5125,15 +5126,19 @@ static BC_STATUS zxc_program_num(BcResult *r, BcNum **num)
5125 case XC_RESULT_ARRAY: 5126 case XC_RESULT_ARRAY:
5126 case XC_RESULT_ARRAY_ELEM: { 5127 case XC_RESULT_ARRAY_ELEM: {
5127 BcVec *v; 5128 BcVec *v;
5128 5129 void *p;
5129 v = xc_program_search(r->d.id.name, r->t == XC_RESULT_VAR); 5130 v = xc_program_search(r->d.id.name, r->t == XC_RESULT_VAR);
5130 5131// dc variables are all stacks, so here we have this:
5132 p = bc_vec_top(v);
5133// TODO: eliminate these stacks for bc-only config?
5131 if (r->t == XC_RESULT_ARRAY_ELEM) { 5134 if (r->t == XC_RESULT_ARRAY_ELEM) {
5132 v = bc_vec_top(v); 5135 v = p;
5133 if (v->len <= r->d.id.idx) bc_array_expand(v, r->d.id.idx + 1); 5136 if (v->len <= r->d.id.idx)
5137 bc_array_expand(v, r->d.id.idx + 1);
5134 *num = bc_vec_item(v, r->d.id.idx); 5138 *num = bc_vec_item(v, r->d.id.idx);
5135 } else 5139 } else {
5136 *num = bc_vec_top(v); 5140 *num = p;
5141 }
5137 break; 5142 break;
5138 } 5143 }
5139#if ENABLE_BC 5144#if ENABLE_BC