diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-28 15:20:44 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-28 15:20:44 -0400 |
commit | fb2877deb18d583791c1d10d43a26822eb2574f7 (patch) | |
tree | 56d4a21737ba846692e0476e3d314fee5a5ee8e5 | |
parent | 7cfbe579dc19483b1ad3aab549e285704a6e6258 (diff) |
modernize bigxcan()
-rw-r--r-- | big.c | 21 |
1 files changed, 14 insertions, 7 deletions
@@ -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; } |