From 787dbbf337bb238bea30d66d4bf43907bca20e19 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 1 Mar 2016 19:22:26 +0100 Subject: Add zcmp, zcmpi, zcmpu, zcmpmag, zset, zseti, and zsetu MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/zsetu.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 src/zsetu.c (limited to 'src/zsetu.c') diff --git a/src/zsetu.c b/src/zsetu.c new file mode 100644 index 0000000..78b78bb --- /dev/null +++ b/src/zsetu.c @@ -0,0 +1,24 @@ +/* See LICENSE file for copyright and license details. */ +#include "internals" + +#define CHARS_PER_TYPE(t) (sizeof(t) / (BITS_PER_CHAR >> 3)) + + +void +zsetu(z_t a, unsigned long long int b) +{ + if (!b) { + SET_SIGNUM(a, 0); + return; + } + if (a->alloced < CHARS_PER_TYPE(b)) { + a->alloced = CHARS_PER_TYPE(b); + a->chars = realloc(a->chars, CHARS_PER_TYPE(b) * sizeof(*(a->chars))) + } + SET_SIGNUM(a, 1); + a->used = 0; + while (b) { + a->chars[a->used++] = (uint32_t)b; + b >>= BITS_PER_CHAR; + } +} -- cgit v1.2.3-70-g09d2