From 7380564933c34cdbeb5cb404aded0e1bdd556c65 Mon Sep 17 00:00:00 2001 From: Alex Shinn Date: Thu, 28 Feb 2019 00:09:08 +0800 Subject: [PATCH] inserting commas in numerator and denominator separately for rationals --- lib/chibi/show/write.scm | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/chibi/show/write.scm b/lib/chibi/show/write.scm index 5571319f..62e2e22c 100644 --- a/lib/chibi/show/write.scm +++ b/lib/chibi/show/write.scm @@ -254,10 +254,6 @@ (cond (precision (gen-fixed n)) - ((and (exact? n) (not (integer? n))) - (string-append (gen-positive-real (numerator n)) - "/" - (gen-positive-real (denominator n)))) ((memv radix (if (exact? n) '(2 8 10 16) '(10))) (number->string n radix)) (else @@ -280,12 +276,16 @@ ;; Post-process a positive real number with decimal char fixup ;; and commas as needed. (define (wrap-comma n) - (let* ((s0 (gen-positive-real n)) - (s1 (if (or (eqv? #\. dec-sep) - (equal? "." dec-sep)) - s0 - (string-replace-all s0 #\. dec-sep)))) - (if comma-rule (insert-commas s1) s1))) + (if (and (not precision) (exact? n) (not (integer? n))) + (string-append (wrap-comma (numerator n)) + "/" + (wrap-comma (denominator n))) + (let* ((s0 (gen-positive-real n)) + (s1 (if (or (eqv? #\. dec-sep) + (equal? "." dec-sep)) + s0 + (string-replace-all s0 #\. dec-sep)))) + (if comma-rule (insert-commas s1) s1)))) ;; Wrap the sign of a real number, forcing a + prefix or using ;; parentheses (n) for negatives according to sign-rule.