From 76d0af5599554d11f104d582cdac8fbaa8569fcc Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 4 Mar 2016 23:50:00 +0100 Subject: Clean up, add zerror and zperror, fix bugs and add more tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zsets.c | 34 +++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) (limited to 'src/zsets.c') diff --git a/src/zsets.c b/src/zsets.c index 24cdd48..2b91864 100644 --- a/src/zsets.c +++ b/src/zsets.c @@ -26,21 +26,45 @@ zsets(z_t a, const char *str) SET_SIGNUM(a, 0); +#if 1 + zset(libzahl_tmp_str_num, libzahl_const_1e19); switch ((str_end - str) % 19) { while (*str) { + zmul(a, a, libzahl_const_1e19); + temp = 0; #define X(n)\ case n:\ temp *= 10, temp += *str++ & 15; - X(0) X(18) X(17) X(16) X(15) X(14) X(13) X(12) X(11) - X(10) X(9) X(8) X(7) X(6) X(5) X(4) X(3) X(2) X(1) + X(0) X(18) X(17) X(16) X(15) X(14) X(13) X(12) X(11) + X(10) X(9) X(8) X(7) X(6) X(5) X(4) X(3) X(2) X(1) #undef X - - zmul(a, a, libzahl_const_1e19); - zsetu(libzahl_tmp_str_num, temp); + if (!temp) + continue; + libzahl_tmp_str_num->chars[0] = (zahl_char_t)temp; + temp >>= BITS_PER_CHAR; + libzahl_tmp_str_num->chars[1] = (zahl_char_t)temp; + libzahl_tmp_str_num->used = 1 + !!temp; zadd(a, a, libzahl_tmp_str_num); + } + } +#else + zset(libzahl_tmp_str_num, libzahl_const_1); + switch ((str_end - str) % 9) { + while (*str) { + zmul(a, a, libzahl_const_1e9); temp = 0; +#define X(n)\ + case n:\ + temp *= 10, temp += *str++ & 15; + X(0) X(8) X(7) X(6) X(5) X(4) X(3) X(2) X(1) +#undef X + if (!temp) + continue; + libzahl_tmp_str_num->chars[0] = temp; + zadd(a, a, libzahl_tmp_str_num); } } +#endif if (neg) SET_SIGNUM(a, -zsignum(a)); -- cgit v1.2.3-70-g09d2