From 5a2c4e97e922720bdf86661a28268fa87b57bddd Mon Sep 17 00:00:00 2001 From: Jakob Kaivo Date: Mon, 28 Mar 2022 15:38:54 -0400 Subject: modernize bigtostr8() --- big.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/big.c b/big.c index 24a4cc6..71fe9c1 100644 --- a/big.c +++ b/big.c @@ -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; } -- cgit v1.2.1