Add some debugging aids to num.c
diff --git a/include/num.h b/include/num.h
index 0e6a0c7..13936fc 100644
--- a/include/num.h
+++ b/include/num.h
@@ -114,6 +114,9 @@
BcNum *restrict base, size_t base_t, bool letter);
BcStatus bc_num_print(BcNum *restrict n, BcNum *restrict base,
size_t base_t, bool newline);
+#ifndef NDEBUG
+void bc_num_printDecimal(const BcNum *restrict n);
+#endif // NDEBUG
#if DC_ENABLED
BcStatus bc_num_stream(BcNum *restrict n, BcNum *restrict base);
#endif // DC_ENABLED
diff --git a/src/num.c b/src/num.c
index 2b8c69c..1ecb3ae 100644
--- a/src/num.c
+++ b/src/num.c
@@ -70,6 +70,7 @@
for (a[i] -= b[i], j = 0; !BC_SIGNAL && a[i + j] < 0;) {
a[i + j++] += 10;
a[i + j] -= 1;
+ assert(a[i + j - 1] >= 0 && a[i + j - 1] < 10);
}
}
return BC_SIGNAL ? BC_STATUS_SIGNAL : BC_STATUS_SUCCESS;
@@ -290,13 +291,17 @@
for (carry = 0, i = 0; !BC_SIGNAL && i < min_rdx + min_int; ++i, ++c->len) {
in = ((unsigned int) ptr_a[i]) + ((unsigned int) ptr_b[i]) + carry;
carry = in / 10;
+ assert(carry >= 0 && carry < 10);
ptr_c[i] = (BcDig) (in % 10);
+ assert(ptr_c[i] >= 0 && ptr_c[i] < 10);
}
for (; !BC_SIGNAL && i < max + min_rdx; ++i, ++c->len) {
in = ((unsigned int) ptr[i]) + carry;
carry = in / 10;
+ assert(carry >= 0 && carry < 10);
ptr_c[i] = (BcDig) (in % 10);
+ assert(ptr_c[i] >= 0 && ptr_c[i] < 10);
}
if (carry) c->num[c->len++] = (BcDig) carry;
@@ -405,10 +410,13 @@
in += ((unsigned int) a->num[j]) * ((unsigned int) b->num[i]);
in += carry;
carry = in / 10;
+ assert(carry >= 0 && carry < 10);
c->num[i + j] = (BcDig) (in % 10);
+ assert(c->num[i + j] >= 0 && c->num[i + j] < 10);
}
c->num[i + j] += (BcDig) carry;
+ assert(c->num[i + j] >= 0 && c->num[i + j] < 10);
len = BC_MAX(len, i + j + !!carry);
}