commit 465749ec6de871ae244ebe6d3264c71eeb728fcc
parent 3cbe3666b87d1c256eddf2d26f2238bfc000083f
Author: Mattias Andrée <maandree@kth.se>
Date: Tue, 1 Mar 2016 19:41:04 +0100
Add typedef zahl_char_t for internal use
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat:
5 files changed, 11 insertions(+), 6 deletions(-)
diff --git a/src/internals.h b/src/internals.h
@@ -2,8 +2,10 @@
#include "../zahl.h"
#define BITS_PER_CHAR 32
-#define FLOOR_BITS_TO_CHARS(bits) ((bits) >> 5)
-#define CEILING_BITS_TO_CHARS(bits) (((bits) + (BITS_PER_CHAR - 1)) >> 5)
+#define LB_BITS_PER_CHAR 5
+
+#define FLOOR_BITS_TO_CHARS(bits) ((bits) >> LB_BITS_PER_CHAR)
+#define CEILING_BITS_TO_CHARS(bits) (((bits) + (BITS_PER_CHAR - 1)) >> LB_BITS_PER_CHAR)
#define BITS_IN_LAST_CHAR(bits) ((bits) & (BITS_PER_CHAR - 1))
#define LIST_TEMPS\
diff --git a/src/zbits.c b/src/zbits.c
@@ -6,7 +6,7 @@ size_t
zbits(z_t a)
{
size_t i;
- uint32_t x;
+ zahl_char_t x;
if (zzero(a)) {
return 1;
}
diff --git a/src/zlsb.c b/src/zlsb.c
@@ -6,7 +6,7 @@ size_t
zlsb(z_t a)
{
size_t i = 0;
- uint32_t x;
+ zahl_char_t x;
if (zzero(a)) {
return SIZE_MAX;
}
diff --git a/src/zsetu.c b/src/zsetu.c
@@ -18,7 +18,7 @@ zsetu(z_t a, unsigned long long int b)
SET_SIGNUM(a, 1);
a->used = 0;
while (b) {
- a->chars[a->used++] = (uint32_t)b;
+ a->chars[a->used++] = (zahl_char_t)b;
b >>= BITS_PER_CHAR;
}
}
diff --git a/zahl.h b/zahl.h
@@ -9,12 +9,15 @@
+/* You should pretend like this typedef does not exist. */
+typedef uint32_t zahl_char_t;
+
/* This structure should be considered opaque. */
typedef struct {
int sign;
size_t used;
size_t alloced;
- uint32_t *chars;
+ zahl_char_t *chars;
} z_t[1];