summaryrefslogtreecommitdiff
path: root/big.c
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 15:20:44 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 15:20:44 -0400
commitfb2877deb18d583791c1d10d43a26822eb2574f7 (patch)
tree56d4a21737ba846692e0476e3d314fee5a5ee8e5 /big.c
parent7cfbe579dc19483b1ad3aab549e285704a6e6258 (diff)
modernize bigxcan()
Diffstat (limited to 'big.c')
-rw-r--r--big.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/big.c b/big.c
index bb72224..642f4b2 100644
--- a/big.c
+++ b/big.c
@@ -764,23 +764,30 @@ word bigscan(char *p)
/* code to handle (unsigned) exponent commented out */
-word bigxscan(p, q) /* read unsigned hex number in '\0'-terminated string p to q */
- /* assumes redundant leading zeros removed */
-char *p, *q;
+/* read unsigned hex number in '\0'-terminated string p to q */
+/* assumes redundant leading zeros removed */
+word bigxscan(char *p, char *q)
{
+ if (*p == '0' && !p[1]) {
+ return make(INT, 0, 0);
+ }
+
word r; /* will hold result */
word *x = &r;
- if (*p == '0' && !p[1])
- return make(INT, 0, 0);
+
while (q > p) {
unsigned long long hold;
q = q - p < 15 ? p : q - 15; /* read upto 15 hex digits from small end */
sscanf(q, "%llx", &hold);
*q = '\0';
word count = 4; /* 15 hex digits => 4 bignum digits */
- while (count-- && !(hold == 0 && q == p))
- *x = make(INT, hold & MAXDIGIT, 0), hold >>= DIGITWIDTH, x = &rest(*x);
+ while (count-- && !(hold == 0 && q == p)) {
+ *x = make(INT, hold & MAXDIGIT, 0);
+ hold >>= DIGITWIDTH;
+ x = &rest(*x);
+ }
}
+
return r;
}