diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-11 19:12:13 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-11 19:12:13 +0100 |
commit | 1aeacefbb33f2590c875c9a3704e485a4a643898 (patch) | |
tree | 64657e33ee78d35e83b53f4f4c855ba3de1e8ee0 | |
parent | c2d15dff42d3f8a805d5437bb5063d3131f800c4 (diff) | |
download | busybox-w32-1aeacefbb33f2590c875c9a3704e485a4a643898.tar.gz busybox-w32-1aeacefbb33f2590c875c9a3704e485a4a643898.tar.bz2 busybox-w32-1aeacefbb33f2590c875c9a3704e485a4a643898.zip |
bc: rename arithmetic calc functions to "z" functions, no code changes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 177 |
1 files changed, 88 insertions, 89 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 6fb6c8139..3ab0bf3b7 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -946,18 +946,17 @@ typedef void (*BcNumDigitOp)(size_t, size_t, bool) FAST_FUNC; | |||
946 | 946 | ||
947 | typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t) FAST_FUNC; | 947 | typedef BcStatus (*BcNumBinaryOp)(BcNum *, BcNum *, BcNum *, size_t) FAST_FUNC; |
948 | 948 | ||
949 | static BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; | 949 | static BcStatus zbc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; |
950 | static BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; | 950 | static BcStatus zbc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; |
951 | static BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; | 951 | static BcStatus zbc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; |
952 | static BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; | 952 | static BcStatus zbc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; |
953 | static BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; | 953 | static BcStatus zbc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; |
954 | static BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; | 954 | static BcStatus zbc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) FAST_FUNC; |
955 | static BcStatus bc_num_sqrt(BcNum *a, BcNum *b, size_t scale); | 955 | static BcStatus zbc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, |
956 | static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, | ||
957 | size_t scale); | 956 | size_t scale); |
958 | 957 | ||
959 | static const BcNumBinaryOp bc_program_ops[] = { | 958 | static const BcNumBinaryOp zbc_program_ops[] = { |
960 | bc_num_pow, bc_num_mul, bc_num_div, bc_num_mod, bc_num_add, bc_num_sub, | 959 | zbc_num_pow, zbc_num_mul, zbc_num_div, zbc_num_mod, zbc_num_add, zbc_num_sub, |
961 | }; | 960 | }; |
962 | 961 | ||
963 | static void fflush_and_check(void) | 962 | static void fflush_and_check(void) |
@@ -1693,7 +1692,7 @@ static BC_STATUS zbc_num_shift(BcNum *n, size_t places) | |||
1693 | # define zbc_num_shift(...) (zbc_num_shift(__VA_ARGS__), BC_STATUS_SUCCESS) | 1692 | # define zbc_num_shift(...) (zbc_num_shift(__VA_ARGS__), BC_STATUS_SUCCESS) |
1694 | #endif | 1693 | #endif |
1695 | 1694 | ||
1696 | static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) | 1695 | static BcStatus zbc_num_inv(BcNum *a, BcNum *b, size_t scale) |
1697 | { | 1696 | { |
1698 | BcNum one; | 1697 | BcNum one; |
1699 | BcDig num[2]; | 1698 | BcDig num[2]; |
@@ -1702,10 +1701,10 @@ static BcStatus bc_num_inv(BcNum *a, BcNum *b, size_t scale) | |||
1702 | one.num = num; | 1701 | one.num = num; |
1703 | bc_num_one(&one); | 1702 | bc_num_one(&one); |
1704 | 1703 | ||
1705 | return bc_num_div(&one, a, b, scale); | 1704 | return zbc_num_div(&one, a, b, scale); |
1706 | } | 1705 | } |
1707 | 1706 | ||
1708 | static FAST_FUNC BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) | 1707 | static FAST_FUNC BcStatus zbc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) |
1709 | { | 1708 | { |
1710 | BcDig *ptr, *ptr_a, *ptr_b, *ptr_c; | 1709 | BcDig *ptr, *ptr_a, *ptr_b, *ptr_c; |
1711 | size_t i, max, min_rdx, min_int, diff, a_int, b_int; | 1710 | size_t i, max, min_rdx, min_int, diff, a_int, b_int; |
@@ -1773,10 +1772,10 @@ static FAST_FUNC BcStatus bc_num_a(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
1773 | 1772 | ||
1774 | if (carry != 0) c->num[c->len++] = (BcDig) carry; | 1773 | if (carry != 0) c->num[c->len++] = (BcDig) carry; |
1775 | 1774 | ||
1776 | return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary() | 1775 | return BC_STATUS_SUCCESS; // can't make void, see zbc_num_binary() |
1777 | } | 1776 | } |
1778 | 1777 | ||
1779 | static FAST_FUNC BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) | 1778 | static FAST_FUNC BcStatus zbc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t sub) |
1780 | { | 1779 | { |
1781 | ssize_t cmp; | 1780 | ssize_t cmp; |
1782 | BcNum *minuend, *subtrahend; | 1781 | BcNum *minuend, *subtrahend; |
@@ -1835,10 +1834,10 @@ static FAST_FUNC BcStatus bc_num_s(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
1835 | 1834 | ||
1836 | bc_num_clean(c); | 1835 | bc_num_clean(c); |
1837 | 1836 | ||
1838 | return BC_STATUS_SUCCESS; // can't make void, see bc_num_binary() | 1837 | return BC_STATUS_SUCCESS; // can't make void, see zbc_num_binary() |
1839 | } | 1838 | } |
1840 | 1839 | ||
1841 | static FAST_FUNC BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, | 1840 | static FAST_FUNC BcStatus zbc_num_k(BcNum *restrict a, BcNum *restrict b, |
1842 | BcNum *restrict c) | 1841 | BcNum *restrict c) |
1843 | { | 1842 | { |
1844 | BcStatus s; | 1843 | BcStatus s; |
@@ -1905,30 +1904,30 @@ static FAST_FUNC BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b, | |||
1905 | bc_num_split(a, max2, &l1, &h1); | 1904 | bc_num_split(a, max2, &l1, &h1); |
1906 | bc_num_split(b, max2, &l2, &h2); | 1905 | bc_num_split(b, max2, &l2, &h2); |
1907 | 1906 | ||
1908 | s = bc_num_add(&h1, &l1, &m1, 0); | 1907 | s = zbc_num_add(&h1, &l1, &m1, 0); |
1909 | if (s) goto err; | 1908 | if (s) goto err; |
1910 | s = bc_num_add(&h2, &l2, &m2, 0); | 1909 | s = zbc_num_add(&h2, &l2, &m2, 0); |
1911 | if (s) goto err; | 1910 | if (s) goto err; |
1912 | 1911 | ||
1913 | s = bc_num_k(&h1, &h2, &z0); | 1912 | s = zbc_num_k(&h1, &h2, &z0); |
1914 | if (s) goto err; | 1913 | if (s) goto err; |
1915 | s = bc_num_k(&m1, &m2, &z1); | 1914 | s = zbc_num_k(&m1, &m2, &z1); |
1916 | if (s) goto err; | 1915 | if (s) goto err; |
1917 | s = bc_num_k(&l1, &l2, &z2); | 1916 | s = zbc_num_k(&l1, &l2, &z2); |
1918 | if (s) goto err; | 1917 | if (s) goto err; |
1919 | 1918 | ||
1920 | s = bc_num_sub(&z1, &z0, &temp, 0); | 1919 | s = zbc_num_sub(&z1, &z0, &temp, 0); |
1921 | if (s) goto err; | 1920 | if (s) goto err; |
1922 | s = bc_num_sub(&temp, &z2, &z1, 0); | 1921 | s = zbc_num_sub(&temp, &z2, &z1, 0); |
1923 | if (s) goto err; | 1922 | if (s) goto err; |
1924 | 1923 | ||
1925 | s = zbc_num_shift(&z0, max2 * 2); | 1924 | s = zbc_num_shift(&z0, max2 * 2); |
1926 | if (s) goto err; | 1925 | if (s) goto err; |
1927 | s = zbc_num_shift(&z1, max2); | 1926 | s = zbc_num_shift(&z1, max2); |
1928 | if (s) goto err; | 1927 | if (s) goto err; |
1929 | s = bc_num_add(&z0, &z1, &temp, 0); | 1928 | s = zbc_num_add(&z0, &z1, &temp, 0); |
1930 | if (s) goto err; | 1929 | if (s) goto err; |
1931 | s = bc_num_add(&temp, &z2, c, 0); | 1930 | s = zbc_num_add(&temp, &z2, c, 0); |
1932 | 1931 | ||
1933 | err: | 1932 | err: |
1934 | bc_num_free(&temp); | 1933 | bc_num_free(&temp); |
@@ -1944,7 +1943,7 @@ err: | |||
1944 | return s; | 1943 | return s; |
1945 | } | 1944 | } |
1946 | 1945 | ||
1947 | static FAST_FUNC BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | 1946 | static FAST_FUNC BcStatus zbc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) |
1948 | { | 1947 | { |
1949 | BcStatus s; | 1948 | BcStatus s; |
1950 | BcNum cpa, cpb; | 1949 | BcNum cpa, cpb; |
@@ -1966,7 +1965,7 @@ static FAST_FUNC BcStatus bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
1966 | if (s) goto err; | 1965 | if (s) goto err; |
1967 | s = zbc_num_shift(&cpb, maxrdx); | 1966 | s = zbc_num_shift(&cpb, maxrdx); |
1968 | if (s) goto err; | 1967 | if (s) goto err; |
1969 | s = bc_num_k(&cpa, &cpb, c); | 1968 | s = zbc_num_k(&cpa, &cpb, c); |
1970 | if (s) goto err; | 1969 | if (s) goto err; |
1971 | 1970 | ||
1972 | maxrdx += scale; | 1971 | maxrdx += scale; |
@@ -1986,7 +1985,7 @@ err: | |||
1986 | return s; | 1985 | return s; |
1987 | } | 1986 | } |
1988 | 1987 | ||
1989 | static FAST_FUNC BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | 1988 | static FAST_FUNC BcStatus zbc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) |
1990 | { | 1989 | { |
1991 | BcStatus s = BC_STATUS_SUCCESS; | 1990 | BcStatus s = BC_STATUS_SUCCESS; |
1992 | BcDig *n, *p, q; | 1991 | BcDig *n, *p, q; |
@@ -2058,7 +2057,7 @@ static FAST_FUNC BcStatus bc_num_d(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
2058 | return s; | 2057 | return s; |
2059 | } | 2058 | } |
2060 | 2059 | ||
2061 | static FAST_FUNC BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c, | 2060 | static FAST_FUNC BcStatus zbc_num_r(BcNum *a, BcNum *b, BcNum *restrict c, |
2062 | BcNum *restrict d, size_t scale, size_t ts) | 2061 | BcNum *restrict d, size_t scale, size_t ts) |
2063 | { | 2062 | { |
2064 | BcStatus s; | 2063 | BcStatus s; |
@@ -2074,14 +2073,14 @@ static FAST_FUNC BcStatus bc_num_r(BcNum *a, BcNum *b, BcNum *restrict c, | |||
2074 | } | 2073 | } |
2075 | 2074 | ||
2076 | bc_num_init(&temp, d->cap); | 2075 | bc_num_init(&temp, d->cap); |
2077 | s = bc_num_d(a, b, c, scale); | 2076 | s = zbc_num_d(a, b, c, scale); |
2078 | if (s) goto err; | 2077 | if (s) goto err; |
2079 | 2078 | ||
2080 | if (scale != 0) scale = ts; | 2079 | if (scale != 0) scale = ts; |
2081 | 2080 | ||
2082 | s = bc_num_m(c, b, &temp, scale); | 2081 | s = zbc_num_m(c, b, &temp, scale); |
2083 | if (s) goto err; | 2082 | if (s) goto err; |
2084 | s = bc_num_sub(a, &temp, d, scale); | 2083 | s = zbc_num_sub(a, &temp, d, scale); |
2085 | if (s) goto err; | 2084 | if (s) goto err; |
2086 | 2085 | ||
2087 | if (ts > d->rdx && d->len) bc_num_extend(d, ts - d->rdx); | 2086 | if (ts > d->rdx && d->len) bc_num_extend(d, ts - d->rdx); |
@@ -2095,20 +2094,20 @@ err: | |||
2095 | return s; | 2094 | return s; |
2096 | } | 2095 | } |
2097 | 2096 | ||
2098 | static FAST_FUNC BcStatus bc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | 2097 | static FAST_FUNC BcStatus zbc_num_rem(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) |
2099 | { | 2098 | { |
2100 | BcStatus s; | 2099 | BcStatus s; |
2101 | BcNum c1; | 2100 | BcNum c1; |
2102 | size_t ts = BC_MAX(scale + b->rdx, a->rdx), len = BC_NUM_MREQ(a, b, ts); | 2101 | size_t ts = BC_MAX(scale + b->rdx, a->rdx), len = BC_NUM_MREQ(a, b, ts); |
2103 | 2102 | ||
2104 | bc_num_init(&c1, len); | 2103 | bc_num_init(&c1, len); |
2105 | s = bc_num_r(a, b, &c1, c, scale, ts); | 2104 | s = zbc_num_r(a, b, &c1, c, scale, ts); |
2106 | bc_num_free(&c1); | 2105 | bc_num_free(&c1); |
2107 | 2106 | ||
2108 | return s; | 2107 | return s; |
2109 | } | 2108 | } |
2110 | 2109 | ||
2111 | static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) | 2110 | static FAST_FUNC BcStatus zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale) |
2112 | { | 2111 | { |
2113 | BcStatus s = BC_STATUS_SUCCESS; | 2112 | BcStatus s = BC_STATUS_SUCCESS; |
2114 | BcNum copy; | 2113 | BcNum copy; |
@@ -2130,7 +2129,7 @@ static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
2130 | if (!b->neg) | 2129 | if (!b->neg) |
2131 | bc_num_copy(c, a); | 2130 | bc_num_copy(c, a); |
2132 | else | 2131 | else |
2133 | s = bc_num_inv(a, c, scale); | 2132 | s = zbc_num_inv(a, c, scale); |
2134 | return s; | 2133 | return s; |
2135 | } | 2134 | } |
2136 | 2135 | ||
@@ -2154,9 +2153,9 @@ static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
2154 | 2153 | ||
2155 | for (powrdx = a->rdx; !(pow & 1); pow >>= 1) { | 2154 | for (powrdx = a->rdx; !(pow & 1); pow >>= 1) { |
2156 | powrdx <<= 1; | 2155 | powrdx <<= 1; |
2157 | s = bc_num_mul(©, ©, ©, powrdx); | 2156 | s = zbc_num_mul(©, ©, ©, powrdx); |
2158 | if (s) goto err; | 2157 | if (s) goto err; |
2159 | // Not needed: bc_num_mul() has a check for ^C: | 2158 | // Not needed: zbc_num_mul() has a check for ^C: |
2160 | //if (G_interrupt) { | 2159 | //if (G_interrupt) { |
2161 | // s = BC_STATUS_FAILURE; | 2160 | // s = BC_STATUS_FAILURE; |
2162 | // goto err; | 2161 | // goto err; |
@@ -2168,15 +2167,15 @@ static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
2168 | for (resrdx = powrdx, pow >>= 1; pow != 0; pow >>= 1) { | 2167 | for (resrdx = powrdx, pow >>= 1; pow != 0; pow >>= 1) { |
2169 | 2168 | ||
2170 | powrdx <<= 1; | 2169 | powrdx <<= 1; |
2171 | s = bc_num_mul(©, ©, ©, powrdx); | 2170 | s = zbc_num_mul(©, ©, ©, powrdx); |
2172 | if (s) goto err; | 2171 | if (s) goto err; |
2173 | 2172 | ||
2174 | if (pow & 1) { | 2173 | if (pow & 1) { |
2175 | resrdx += powrdx; | 2174 | resrdx += powrdx; |
2176 | s = bc_num_mul(c, ©, c, resrdx); | 2175 | s = zbc_num_mul(c, ©, c, resrdx); |
2177 | if (s) goto err; | 2176 | if (s) goto err; |
2178 | } | 2177 | } |
2179 | // Not needed: bc_num_mul() has a check for ^C: | 2178 | // Not needed: zbc_num_mul() has a check for ^C: |
2180 | //if (G_interrupt) { | 2179 | //if (G_interrupt) { |
2181 | // s = BC_STATUS_FAILURE; | 2180 | // s = BC_STATUS_FAILURE; |
2182 | // goto err; | 2181 | // goto err; |
@@ -2184,7 +2183,7 @@ static FAST_FUNC BcStatus bc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size_t | |||
2184 | } | 2183 | } |
2185 | 2184 | ||
2186 | if (neg) { | 2185 | if (neg) { |
2187 | s = bc_num_inv(c, c, scale); | 2186 | s = zbc_num_inv(c, c, scale); |
2188 | if (s) goto err; | 2187 | if (s) goto err; |
2189 | } | 2188 | } |
2190 | 2189 | ||
@@ -2199,7 +2198,7 @@ err: | |||
2199 | return s; | 2198 | return s; |
2200 | } | 2199 | } |
2201 | 2200 | ||
2202 | static BcStatus bc_num_binary(BcNum *a, BcNum *b, BcNum *c, size_t scale, | 2201 | static BcStatus zbc_num_binary(BcNum *a, BcNum *b, BcNum *c, size_t scale, |
2203 | BcNumBinaryOp op, size_t req) | 2202 | BcNumBinaryOp op, size_t req) |
2204 | { | 2203 | { |
2205 | BcStatus s; | 2204 | BcStatus s; |
@@ -2322,11 +2321,11 @@ static BC_STATUS zbc_num_printNum(BcNum *n, BcNum *base, size_t width, BcNumDigi | |||
2322 | bc_num_one(&frac_len); | 2321 | bc_num_one(&frac_len); |
2323 | 2322 | ||
2324 | bc_num_truncate(&intp, intp.rdx); | 2323 | bc_num_truncate(&intp, intp.rdx); |
2325 | s = bc_num_sub(n, &intp, &fracp, 0); | 2324 | s = zbc_num_sub(n, &intp, &fracp, 0); |
2326 | if (s) goto err; | 2325 | if (s) goto err; |
2327 | 2326 | ||
2328 | while (intp.len != 0) { | 2327 | while (intp.len != 0) { |
2329 | s = bc_num_divmod(&intp, base, &intp, &digit, 0); | 2328 | s = zbc_num_divmod(&intp, base, &intp, &digit, 0); |
2330 | if (s) goto err; | 2329 | if (s) goto err; |
2331 | s = zbc_num_ulong(&digit, &dig); | 2330 | s = zbc_num_ulong(&digit, &dig); |
2332 | if (s) goto err; | 2331 | if (s) goto err; |
@@ -2341,15 +2340,15 @@ static BC_STATUS zbc_num_printNum(BcNum *n, BcNum *base, size_t width, BcNumDigi | |||
2341 | if (!n->rdx) goto err; | 2340 | if (!n->rdx) goto err; |
2342 | 2341 | ||
2343 | for (radix = true; frac_len.len <= n->rdx; radix = false) { | 2342 | for (radix = true; frac_len.len <= n->rdx; radix = false) { |
2344 | s = bc_num_mul(&fracp, base, &fracp, n->rdx); | 2343 | s = zbc_num_mul(&fracp, base, &fracp, n->rdx); |
2345 | if (s) goto err; | 2344 | if (s) goto err; |
2346 | s = zbc_num_ulong(&fracp, &dig); | 2345 | s = zbc_num_ulong(&fracp, &dig); |
2347 | if (s) goto err; | 2346 | if (s) goto err; |
2348 | bc_num_ulong2num(&intp, dig); | 2347 | bc_num_ulong2num(&intp, dig); |
2349 | s = bc_num_sub(&fracp, &intp, &fracp, 0); | 2348 | s = zbc_num_sub(&fracp, &intp, &fracp, 0); |
2350 | if (s) goto err; | 2349 | if (s) goto err; |
2351 | print(dig, width, radix); | 2350 | print(dig, width, radix); |
2352 | s = bc_num_mul(&frac_len, base, &frac_len, 0); | 2351 | s = zbc_num_mul(&frac_len, base, &frac_len, 0); |
2353 | if (s) goto err; | 2352 | if (s) goto err; |
2354 | } | 2353 | } |
2355 | 2354 | ||
@@ -2493,10 +2492,10 @@ static void bc_num_parseBase(BcNum *n, const char *val, BcNum *base) | |||
2493 | 2492 | ||
2494 | v = (unsigned long) (c <= '9' ? c - '0' : c - 'A' + 10); | 2493 | v = (unsigned long) (c <= '9' ? c - '0' : c - 'A' + 10); |
2495 | 2494 | ||
2496 | s = bc_num_mul(n, base, &mult, 0); | 2495 | s = zbc_num_mul(n, base, &mult, 0); |
2497 | if (s) goto int_err; | 2496 | if (s) goto int_err; |
2498 | bc_num_ulong2num(&temp, v); | 2497 | bc_num_ulong2num(&temp, v); |
2499 | s = bc_num_add(&mult, &temp, n, 0); | 2498 | s = zbc_num_add(&mult, &temp, n, 0); |
2500 | if (s) goto int_err; | 2499 | if (s) goto int_err; |
2501 | } | 2500 | } |
2502 | 2501 | ||
@@ -2512,18 +2511,18 @@ static void bc_num_parseBase(BcNum *n, const char *val, BcNum *base) | |||
2512 | 2511 | ||
2513 | v = (unsigned long) (c <= '9' ? c - '0' : c - 'A' + 10); | 2512 | v = (unsigned long) (c <= '9' ? c - '0' : c - 'A' + 10); |
2514 | 2513 | ||
2515 | s = bc_num_mul(&result, base, &result, 0); | 2514 | s = zbc_num_mul(&result, base, &result, 0); |
2516 | if (s) goto err; | 2515 | if (s) goto err; |
2517 | bc_num_ulong2num(&temp, v); | 2516 | bc_num_ulong2num(&temp, v); |
2518 | s = bc_num_add(&result, &temp, &result, 0); | 2517 | s = zbc_num_add(&result, &temp, &result, 0); |
2519 | if (s) goto err; | 2518 | if (s) goto err; |
2520 | s = bc_num_mul(&mult, base, &mult, 0); | 2519 | s = zbc_num_mul(&mult, base, &mult, 0); |
2521 | if (s) goto err; | 2520 | if (s) goto err; |
2522 | } | 2521 | } |
2523 | 2522 | ||
2524 | s = bc_num_div(&result, &mult, &result, digits); | 2523 | s = zbc_num_div(&result, &mult, &result, digits); |
2525 | if (s) goto err; | 2524 | if (s) goto err; |
2526 | s = bc_num_add(n, &result, n, digits); | 2525 | s = zbc_num_add(n, &result, n, digits); |
2527 | if (s) goto err; | 2526 | if (s) goto err; |
2528 | 2527 | ||
2529 | if (n->len != 0) { | 2528 | if (n->len != 0) { |
@@ -2584,44 +2583,44 @@ static BC_STATUS zbc_num_print(BcNum *n, bool newline) | |||
2584 | # define zbc_num_print(...) (zbc_num_print(__VA_ARGS__), BC_STATUS_SUCCESS) | 2583 | # define zbc_num_print(...) (zbc_num_print(__VA_ARGS__), BC_STATUS_SUCCESS) |
2585 | #endif | 2584 | #endif |
2586 | 2585 | ||
2587 | static FAST_FUNC BcStatus bc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2586 | static FAST_FUNC BcStatus zbc_num_add(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
2588 | { | 2587 | { |
2589 | BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_a : bc_num_s; | 2588 | BcNumBinaryOp op = (!a->neg == !b->neg) ? zbc_num_a : zbc_num_s; |
2590 | (void) scale; | 2589 | (void) scale; |
2591 | return bc_num_binary(a, b, c, false, op, BC_NUM_AREQ(a, b)); | 2590 | return zbc_num_binary(a, b, c, false, op, BC_NUM_AREQ(a, b)); |
2592 | } | 2591 | } |
2593 | 2592 | ||
2594 | static FAST_FUNC BcStatus bc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2593 | static FAST_FUNC BcStatus zbc_num_sub(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
2595 | { | 2594 | { |
2596 | BcNumBinaryOp op = (!a->neg == !b->neg) ? bc_num_s : bc_num_a; | 2595 | BcNumBinaryOp op = (!a->neg == !b->neg) ? zbc_num_s : zbc_num_a; |
2597 | (void) scale; | 2596 | (void) scale; |
2598 | return bc_num_binary(a, b, c, true, op, BC_NUM_AREQ(a, b)); | 2597 | return zbc_num_binary(a, b, c, true, op, BC_NUM_AREQ(a, b)); |
2599 | } | 2598 | } |
2600 | 2599 | ||
2601 | static FAST_FUNC BcStatus bc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2600 | static FAST_FUNC BcStatus zbc_num_mul(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
2602 | { | 2601 | { |
2603 | size_t req = BC_NUM_MREQ(a, b, scale); | 2602 | size_t req = BC_NUM_MREQ(a, b, scale); |
2604 | return bc_num_binary(a, b, c, scale, bc_num_m, req); | 2603 | return zbc_num_binary(a, b, c, scale, zbc_num_m, req); |
2605 | } | 2604 | } |
2606 | 2605 | ||
2607 | static FAST_FUNC BcStatus bc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2606 | static FAST_FUNC BcStatus zbc_num_div(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
2608 | { | 2607 | { |
2609 | size_t req = BC_NUM_MREQ(a, b, scale); | 2608 | size_t req = BC_NUM_MREQ(a, b, scale); |
2610 | return bc_num_binary(a, b, c, scale, bc_num_d, req); | 2609 | return zbc_num_binary(a, b, c, scale, zbc_num_d, req); |
2611 | } | 2610 | } |
2612 | 2611 | ||
2613 | static FAST_FUNC BcStatus bc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2612 | static FAST_FUNC BcStatus zbc_num_mod(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
2614 | { | 2613 | { |
2615 | size_t req = BC_NUM_MREQ(a, b, scale); | 2614 | size_t req = BC_NUM_MREQ(a, b, scale); |
2616 | return bc_num_binary(a, b, c, scale, bc_num_rem, req); | 2615 | return zbc_num_binary(a, b, c, scale, zbc_num_rem, req); |
2617 | } | 2616 | } |
2618 | 2617 | ||
2619 | static FAST_FUNC BcStatus bc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) | 2618 | static FAST_FUNC BcStatus zbc_num_pow(BcNum *a, BcNum *b, BcNum *c, size_t scale) |
2620 | { | 2619 | { |
2621 | return bc_num_binary(a, b, c, scale, bc_num_p, a->len * b->len + 1); | 2620 | return zbc_num_binary(a, b, c, scale, zbc_num_p, a->len * b->len + 1); |
2622 | } | 2621 | } |
2623 | 2622 | ||
2624 | static BcStatus bc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale) | 2623 | static BcStatus zbc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale) |
2625 | { | 2624 | { |
2626 | BcStatus s; | 2625 | BcStatus s; |
2627 | BcNum num1, num2, half, f, fprime, *x0, *x1, *temp; | 2626 | BcNum num1, num2, half, f, fprime, *x0, *x1, *temp; |
@@ -2684,11 +2683,11 @@ static BcStatus bc_num_sqrt(BcNum *a, BcNum *restrict b, size_t scale) | |||
2684 | 2683 | ||
2685 | while (cmp != 0 || digs < len) { | 2684 | while (cmp != 0 || digs < len) { |
2686 | 2685 | ||
2687 | s = bc_num_div(a, x0, &f, resrdx); | 2686 | s = zbc_num_div(a, x0, &f, resrdx); |
2688 | if (s) goto err; | 2687 | if (s) goto err; |
2689 | s = bc_num_add(x0, &f, &fprime, resrdx); | 2688 | s = zbc_num_add(x0, &f, &fprime, resrdx); |
2690 | if (s) goto err; | 2689 | if (s) goto err; |
2691 | s = bc_num_mul(&fprime, &half, x1, resrdx); | 2690 | s = zbc_num_mul(&fprime, &half, x1, resrdx); |
2692 | if (s) goto err; | 2691 | if (s) goto err; |
2693 | 2692 | ||
2694 | cmp = bc_num_cmp(x1, x0); | 2693 | cmp = bc_num_cmp(x1, x0); |
@@ -2723,7 +2722,7 @@ err: | |||
2723 | return s; | 2722 | return s; |
2724 | } | 2723 | } |
2725 | 2724 | ||
2726 | static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, | 2725 | static BcStatus zbc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, |
2727 | size_t scale) | 2726 | size_t scale) |
2728 | { | 2727 | { |
2729 | BcStatus s; | 2728 | BcStatus s; |
@@ -2742,7 +2741,7 @@ static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, | |||
2742 | bc_num_expand(c, len); | 2741 | bc_num_expand(c, len); |
2743 | } | 2742 | } |
2744 | 2743 | ||
2745 | s = bc_num_r(ptr_a, b, c, d, scale, ts); | 2744 | s = zbc_num_r(ptr_a, b, c, d, scale, ts); |
2746 | 2745 | ||
2747 | if (init) bc_num_free(&num2); | 2746 | if (init) bc_num_free(&num2); |
2748 | 2747 | ||
@@ -2750,7 +2749,7 @@ static BcStatus bc_num_divmod(BcNum *a, BcNum *b, BcNum *c, BcNum *d, | |||
2750 | } | 2749 | } |
2751 | 2750 | ||
2752 | #if ENABLE_DC | 2751 | #if ENABLE_DC |
2753 | static BcStatus bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d) | 2752 | static BcStatus zbc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d) |
2754 | { | 2753 | { |
2755 | BcStatus s; | 2754 | BcStatus s; |
2756 | BcNum base, exp, two, temp; | 2755 | BcNum base, exp, two, temp; |
@@ -2772,25 +2771,25 @@ static BcStatus bc_num_modexp(BcNum *a, BcNum *b, BcNum *c, BcNum *restrict d) | |||
2772 | two.num[0] = 2; | 2771 | two.num[0] = 2; |
2773 | bc_num_one(d); | 2772 | bc_num_one(d); |
2774 | 2773 | ||
2775 | s = bc_num_rem(a, c, &base, 0); | 2774 | s = zbc_num_rem(a, c, &base, 0); |
2776 | if (s) goto err; | 2775 | if (s) goto err; |
2777 | bc_num_copy(&exp, b); | 2776 | bc_num_copy(&exp, b); |
2778 | 2777 | ||
2779 | while (exp.len != 0) { | 2778 | while (exp.len != 0) { |
2780 | 2779 | ||
2781 | s = bc_num_divmod(&exp, &two, &exp, &temp, 0); | 2780 | s = zbc_num_divmod(&exp, &two, &exp, &temp, 0); |
2782 | if (s) goto err; | 2781 | if (s) goto err; |
2783 | 2782 | ||
2784 | if (BC_NUM_ONE(&temp)) { | 2783 | if (BC_NUM_ONE(&temp)) { |
2785 | s = bc_num_mul(d, &base, &temp, 0); | 2784 | s = zbc_num_mul(d, &base, &temp, 0); |
2786 | if (s) goto err; | 2785 | if (s) goto err; |
2787 | s = bc_num_rem(&temp, c, d, 0); | 2786 | s = zbc_num_rem(&temp, c, d, 0); |
2788 | if (s) goto err; | 2787 | if (s) goto err; |
2789 | } | 2788 | } |
2790 | 2789 | ||
2791 | s = bc_num_mul(&base, &base, &temp, 0); | 2790 | s = zbc_num_mul(&base, &base, &temp, 0); |
2792 | if (s) goto err; | 2791 | if (s) goto err; |
2793 | s = bc_num_rem(&temp, c, &base, 0); | 2792 | s = zbc_num_rem(&temp, c, &base, 0); |
2794 | if (s) goto err; | 2793 | if (s) goto err; |
2795 | } | 2794 | } |
2796 | 2795 | ||
@@ -5631,7 +5630,7 @@ static BcStatus bc_program_op(char inst) | |||
5631 | if (s) return s; | 5630 | if (s) return s; |
5632 | bc_num_init_DEF_SIZE(&res.d.n); | 5631 | bc_num_init_DEF_SIZE(&res.d.n); |
5633 | 5632 | ||
5634 | s = bc_program_ops[inst - BC_INST_POWER](n1, n2, &res.d.n, G.prog.scale); | 5633 | s = zbc_program_ops[inst - BC_INST_POWER](n1, n2, &res.d.n, G.prog.scale); |
5635 | if (s) goto err; | 5634 | if (s) goto err; |
5636 | bc_program_binOpRetire(&res); | 5635 | bc_program_binOpRetire(&res); |
5637 | 5636 | ||
@@ -6064,7 +6063,7 @@ static BcStatus bc_program_assign(char inst) | |||
6064 | if (assign) | 6063 | if (assign) |
6065 | bc_num_copy(l, r); | 6064 | bc_num_copy(l, r); |
6066 | else | 6065 | else |
6067 | s = bc_program_ops[inst - BC_INST_ASSIGN_POWER](l, r, l, G.prog.scale); | 6066 | s = zbc_program_ops[inst - BC_INST_ASSIGN_POWER](l, r, l, G.prog.scale); |
6068 | 6067 | ||
6069 | if (s) return s; | 6068 | if (s) return s; |
6070 | #else | 6069 | #else |
@@ -6392,7 +6391,7 @@ static BcStatus bc_program_builtin(char inst) | |||
6392 | 6391 | ||
6393 | bc_num_init_DEF_SIZE(&res.d.n); | 6392 | bc_num_init_DEF_SIZE(&res.d.n); |
6394 | 6393 | ||
6395 | if (inst == BC_INST_SQRT) s = bc_num_sqrt(num, &res.d.n, G.prog.scale); | 6394 | if (inst == BC_INST_SQRT) s = zbc_num_sqrt(num, &res.d.n, G.prog.scale); |
6396 | #if ENABLE_BC | 6395 | #if ENABLE_BC |
6397 | else if (len != 0 && opnd->t == BC_RESULT_ARRAY) { | 6396 | else if (len != 0 && opnd->t == BC_RESULT_ARRAY) { |
6398 | bc_num_ulong2num(&res.d.n, (unsigned long) ((BcVec *) num)->len); | 6397 | bc_num_ulong2num(&res.d.n, (unsigned long) ((BcVec *) num)->len); |
@@ -6430,7 +6429,7 @@ static BcStatus bc_program_divmod(void) | |||
6430 | bc_num_init_DEF_SIZE(&res.d.n); | 6429 | bc_num_init_DEF_SIZE(&res.d.n); |
6431 | bc_num_init(&res2.d.n, n2->len); | 6430 | bc_num_init(&res2.d.n, n2->len); |
6432 | 6431 | ||
6433 | s = bc_num_divmod(n1, n2, &res2.d.n, &res.d.n, G.prog.scale); | 6432 | s = zbc_num_divmod(n1, n2, &res2.d.n, &res.d.n, G.prog.scale); |
6434 | if (s) goto err; | 6433 | if (s) goto err; |
6435 | 6434 | ||
6436 | bc_program_binOpRetire(&res2); | 6435 | bc_program_binOpRetire(&res2); |
@@ -6477,7 +6476,7 @@ static BcStatus bc_program_modexp(void) | |||
6477 | } | 6476 | } |
6478 | 6477 | ||
6479 | bc_num_init(&res.d.n, n3->len); | 6478 | bc_num_init(&res.d.n, n3->len); |
6480 | s = bc_num_modexp(n1, n2, n3, &res.d.n); | 6479 | s = zbc_num_modexp(n1, n2, n3, &res.d.n); |
6481 | if (s) goto err; | 6480 | if (s) goto err; |
6482 | 6481 | ||
6483 | bc_vec_pop(&G.prog.results); | 6482 | bc_vec_pop(&G.prog.results); |
@@ -6525,7 +6524,7 @@ static BcStatus bc_program_asciify(void) | |||
6525 | bc_num_copy(&n, num); | 6524 | bc_num_copy(&n, num); |
6526 | bc_num_truncate(&n, n.rdx); | 6525 | bc_num_truncate(&n, n.rdx); |
6527 | 6526 | ||
6528 | s = bc_num_mod(&n, &G.prog.strmb, &n, 0); | 6527 | s = zbc_num_mod(&n, &G.prog.strmb, &n, 0); |
6529 | if (s) goto num_err; | 6528 | if (s) goto num_err; |
6530 | s = zbc_num_ulong(&n, &val); | 6529 | s = zbc_num_ulong(&n, &val); |
6531 | if (s) goto num_err; | 6530 | if (s) goto num_err; |