summaryrefslogtreecommitdiffstats
path: root/pbn_init.c
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2012-03-12 21:59:00 -0700
committerH. Peter Anvin <hpa@zytor.com>2012-03-12 21:59:00 -0700
commitd58300585648dc798ac0a6d1d55590ea9ce26cd3 (patch)
tree30bf479fa0c6d450ec12d3342600a9df99e233f5 /pbn_init.c
parent488dc320879f268c810f021d5e063c60afbac0cf (diff)
downloadpbn-d58300585648dc798ac0a6d1d55590ea9ce26cd3.tar.gz
pbn-d58300585648dc798ac0a6d1d55590ea9ce26cd3.tar.xz
pbn-d58300585648dc798ac0a6d1d55590ea9ce26cd3.zip
Fix the division case where the denominator is a single limb
The code for Knuth-D assumes a denominator of >= 2 limbs; test for this and fall back to a simple divide loop for a single-limb denominator.
Diffstat (limited to 'pbn_init.c')
-rw-r--r--pbn_init.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/pbn_init.c b/pbn_init.c
index a0a252b..b34f218 100644
--- a/pbn_init.c
+++ b/pbn_init.c
@@ -103,6 +103,17 @@ struct pbn *pbn_int(pbn_satom_t v)
return pbn;
}
+struct pbn *pbn_uint(pbn_atom_t v)
+{
+ struct pbn *pbn = pbn_new(1);
+ if (!pbn)
+ return NULL;
+
+ pbn->num[0] = v;
+ pbn->bits = v ? pbn_ilog2p1(v) : 0;
+ return pbn;
+}
+
/* Produce a duplicate */
struct pbn *pbn_dup(const struct pbn *src)
{