aboutsummaryrefslogtreecommitdiffstats
path: root/src/zstr.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2016-03-12 20:22:11 +0100
committerMattias Andrée <maandree@kth.se>2016-03-12 20:22:11 +0100
commit5e77b994435be4bef66ff596bf931e1fff97a77c (patch)
tree3095688b2163b07057a948e859a0d2dff44511e6 /src/zstr.c
parentAdd simple benchmarker (diff)
downloadlibzahl-5e77b994435be4bef66ff596bf931e1fff97a77c.tar.gz
libzahl-5e77b994435be4bef66ff596bf931e1fff97a77c.tar.bz2
libzahl-5e77b994435be4bef66ff596bf931e1fff97a77c.tar.xz
64-bit chars out-perform 32-bit chars on almost all operations, and on all expensive operations
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/zstr.c')
-rw-r--r--src/zstr.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/zstr.c b/src/zstr.c
index f7273ce..81a9674 100644
--- a/src/zstr.c
+++ b/src/zstr.c
@@ -6,16 +6,16 @@
#define num libzahl_tmp_str_num
#define rem libzahl_tmp_str_rem
-/* All 9 you see here is derived from that 10⁹ is the largest
- * power of than < 2³², and 32 is the number of bits in
- * zahl_char_t. If zahl_char_t is chanced, the value 9, and
- * the cast to unsigned long must be changed accordingly. */
+/* All 19 you see here is derived from that 10¹⁹ is the largest
+ * power of than < 2⁶⁴, and 64 is the number of bits in
+ * zahl_char_t. If zahl_char_t is chanced, the value 19, and
+ * the cast to unsigned long long must be changed accordingly. */
char *
zstr(z_t a, char *b)
{
- char buf[9 + 1];
+ char buf[19 + 1];
size_t n, len;
char overridden = 0;
int neg;
@@ -44,17 +44,17 @@ zstr(z_t a, char *b)
b[0] = '-';
b += neg;
n -= neg;
- n = n > 9 ? (n - 9) : 0;
+ n = n > 19 ? (n - 19) : 0;
for (;;) {
- zdivmod(num, rem, num, libzahl_const_1e9);
+ zdivmod(num, rem, num, libzahl_const_1e19);
if (!zzero(num)) {
- sprintf(b + n, "%09lu", zzero(rem) ? 0UL : (unsigned long)(rem->chars[0]));
- b[n + 9] = overridden;
+ sprintf(b + n, "%019llu", zzero(rem) ? 0ULL : (unsigned long long)(rem->chars[0]));
+ b[n + 19] = overridden;
overridden = b[n];
- n = n > 9 ? (n - 9) : 0;
+ n = n > 19 ? (n - 19) : 0;
} else {
- len = (size_t)sprintf(buf, "%lu", (unsigned long)(rem->chars[0]));
+ len = (size_t)sprintf(buf, "%llu", (unsigned long long)(rem->chars[0]));
if (overridden)
buf[len] = b[n + len];
memcpy(b + n, buf, len + 1);