aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/internals.h5
-rw-r--r--src/zstr_length.c28
2 files changed, 32 insertions, 1 deletions
diff --git a/src/internals.h b/src/internals.h
index df973fb..a544924 100644
--- a/src/internals.h
+++ b/src/internals.h
@@ -9,7 +9,10 @@
#define BITS_IN_LAST_CHAR(bits) ((bits) & (BITS_PER_CHAR - 1))
#define LIST_TEMPS\
- X(libzahl_tmp_cmp)
+ X(libzahl_tmp_cmp)\
+ X(libzahl_tmp_str_num)\
+ X(libzahl_tmp_str_mag)\
+ X(libzahl_tmp_str_div)
#define X(x) extern z_t x;
LIST_TEMPS
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;
+}