diff options
-rw-r--r-- | big.c | 23 |
1 files changed, 15 insertions, 8 deletions
@@ -994,22 +994,29 @@ word bigtostrx(word x) return s ? cons('-', r) : r; } -word bigtostr8(x) /* integer to octal string (as Miranda list) */ -word x; +/* integer to octal string (as Miranda list) */ +word bigtostr8(word x) { extern char *dicp; - word r = NIL, s = big_is_negative(x); + word r = NIL; + word s = big_is_negative(x); + while (x) { char *q = dicp + 5; sprintf(dicp, "%.5lo", digit0(x)); - while (--q >= dicp) + + while (--q >= dicp) { r = cons(*q, r); + } + x = rest(x); } - 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('o', r)); - if (s) - r = cons('-', r); - return (r); + + return s ? cons('-', r) : r; } |