diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-22 21:45:18 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-22 21:45:18 +0100 |
commit | 2ea8ddf8c245dd160eacf35409572c28345506f7 (patch) | |
tree | a17cfa8d8a63045d47a10a8a1e72f91baf4a8404 /miscutils/bc.c | |
parent | 1557b76edde8bc810f82ac67e3b83b2d6ccce51c (diff) | |
download | busybox-w32-2ea8ddf8c245dd160eacf35409572c28345506f7.tar.gz busybox-w32-2ea8ddf8c245dd160eacf35409572c28345506f7.tar.bz2 busybox-w32-2ea8ddf8c245dd160eacf35409572c28345506f7.zip |
bc: do not disallow powers to N.0000 degree - it's even shorter code
function old new delta
zbc_num_p 440 424 -16
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to '')
-rw-r--r-- | miscutils/bc.c | 7 |
1 files changed, 4 insertions, 3 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 876244b34..d7595ce8e 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -2089,7 +2089,8 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size | |||
2089 | size_t i, powrdx, resrdx; | 2089 | size_t i, powrdx, resrdx; |
2090 | bool neg; | 2090 | bool neg; |
2091 | 2091 | ||
2092 | if (b->rdx) RETURN_STATUS(bc_error("non integer number")); | 2092 | // GNU bc does not allow 2^2.0. We do. |
2093 | // if (b->rdx) RETURN_STATUS(bc_error("non integer number")); | ||
2093 | 2094 | ||
2094 | if (b->len == 0) { | 2095 | if (b->len == 0) { |
2095 | bc_num_one(c); | 2096 | bc_num_one(c); |
@@ -2109,9 +2110,10 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size | |||
2109 | 2110 | ||
2110 | neg = b->neg; | 2111 | neg = b->neg; |
2111 | b->neg = false; | 2112 | b->neg = false; |
2112 | |||
2113 | s = zbc_num_ulong(b, &pow); | 2113 | s = zbc_num_ulong(b, &pow); |
2114 | b->neg = neg; | ||
2114 | if (s) RETURN_STATUS(s); | 2115 | if (s) RETURN_STATUS(s); |
2116 | // b is not used beyond this point | ||
2115 | 2117 | ||
2116 | bc_num_init(©, a->len); | 2118 | bc_num_init(©, a->len); |
2117 | bc_num_copy(©, a); | 2119 | bc_num_copy(©, a); |
@@ -2123,7 +2125,6 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size | |||
2123 | scale = a->rdx * pow; | 2125 | scale = a->rdx * pow; |
2124 | } | 2126 | } |
2125 | 2127 | ||
2126 | b->neg = neg; | ||
2127 | 2128 | ||
2128 | for (powrdx = a->rdx; !(pow & 1); pow >>= 1) { | 2129 | for (powrdx = a->rdx; !(pow & 1); pow >>= 1) { |
2129 | powrdx <<= 1; | 2130 | powrdx <<= 1; |