diff options
-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; } |