diff options
author | Jakob Kaivo <jkk@ung.org> | 2022-03-28 15:38:54 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2022-03-28 15:38:54 -0400 |
commit | 5a2c4e97e922720bdf86661a28268fa87b57bddd (patch) | |
tree | 20a23aded8aadfa23a98b3807263314f0c5c20dd | |
parent | 68e454c6b67bd26f11bfedc6a571f41bfa13d3d9 (diff) |
modernize bigtostr8()
-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; } |