aboutsummaryrefslogtreecommitdiffstats
path: root/src/zstr_length.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-02 09:11:48 +0100
committerMattias Andrée <maandree@kth.se>2016-03-02 09:12:31 +0100
commitea2d6c93d28a9c5af94035057c52c36f0618ba2c (patch)
tree73cc4b6cbb66e623ae6f5ee933c489bae97a01d8 /src/zstr_length.c
parentWhy zbits returns 1 for 0 (diff)
downloadlibzahl-ea2d6c93d28a9c5af94035057c52c36f0618ba2c.tar.gz
libzahl-ea2d6c93d28a9c5af94035057c52c36f0618ba2c.tar.bz2
libzahl-ea2d6c93d28a9c5af94035057c52c36f0618ba2c.tar.xz
zstr_length_positive is safe for non-positive, hence rename to zstr_length; and add zstr_length
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r--src/zstr_length.c28
1 files changed, 28 insertions, 0 deletions
diff --git a/src/zstr_length.c b/src/zstr_length.c
new file mode 100644
index 0000000..4edabb0
--- /dev/null
+++ b/src/zstr_length.c
@@ -0,0 +1,28 @@
+/* See LICENSE file for copyright and license details. */
+#include "internals"
+
+#define num libzahl_tmp_str_num
+#define mag libzahl_tmp_str_mag
+#define div libzahl_tmp_str_div
+
+
+size_t
+zstr_length(z_t a, unsigned long long int radix)
+{
+ size_t size_total = 1, size_temp;
+ zset(num, a);
+ while (!zzero(num)) {
+ zsetu(mag, radix);
+ zset(div, mag);
+ size_temp = 1;
+ while (zcmpmag(mag, num) <= 0) {
+ zset(div, mag);
+ zsqr(mag, mag);
+ size_temp <<= 1;
+ }
+ size_temp >>= 1;
+ size_total += size_temp;
+ zdiv(num, num, div);
+ }
+ return size_total;
+}