summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJakob Kaivo <jkk@ung.org>2022-03-28 15:38:54 -0400
committerJakob Kaivo <jkk@ung.org>2022-03-28 15:38:54 -0400
commit5a2c4e97e922720bdf86661a28268fa87b57bddd (patch)
tree20a23aded8aadfa23a98b3807263314f0c5c20dd
parent68e454c6b67bd26f11bfedc6a571f41bfa13d3d9 (diff)
modernize bigtostr8()
-rw-r--r--big.c23
1 files 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;
}