summaryrefslogtreecommitdiff
path: root/big.c
diff options
context:
space:
mode:
Diffstat (limited to 'big.c')
-rw-r--r--big.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/big.c b/big.c
index d7ffd02..24a4cc6 100644
--- a/big.c
+++ b/big.c
@@ -959,31 +959,39 @@ word bigtostr(word x)
}
}
-word bigtostrx(x) /* integer to hexadecimal string (as Miranda list) */
-word x;
+/* integer to hexadecimal string (as Miranda list) */
+word bigtostrx(word x)
{
extern char *dicp;
- word r = NIL, s = big_is_negative(x);
+ word r = NIL;
+ word s = big_is_negative(x);
+
while (x) {
word count = 4; /* 60 bits => 20 octal digits => 4 bignum digits */
unsigned long long factor = 1;
unsigned long long hold = 0;
- while (count-- && x) /* calculate value of (upto) 4 bignum digits */
- hold = hold + factor * digit0(x),
- /* printf("::%llx\n",hold), /* DEBUG */
- factor <<= 15, x = rest(x);
+
+ /* calculate value of (upto) 4 bignum digits */
+ while (count-- && x) {
+ hold = hold + factor * digit0(x);
+ factor <<= 15;
+ x = rest(x);
+ }
+
sprintf(dicp, "%.15llx", hold); /* 15 hex digits = 60 bits */
- /* printf(":::%s\n",dicp); /* DEBUG */
char *q = dicp + 15;
- while (--q >= dicp)
+ while (--q >= dicp) {
r = cons(*q, r);
+ }
}
- while (digit(r) == '0' && rest(r) != NIL)
+
+ while (digit(r) == '0' && rest(r) != NIL) {
r = rest(r); /* remove redundant leading 0's */
+ }
+
r = cons('0', cons('x', r));
- if (s)
- r = cons('-', r);
- return (r);
+
+ return s ? cons('-', r) : r;
}
word bigtostr8(x) /* integer to octal string (as Miranda list) */