updating sign-rule to respect finalized SRFI 159

This commit is contained in:
Alex Shinn 2019-03-10 14:50:44 +08:00
parent e921fdb95c
commit bd78ebeed7
2 changed files with 14 additions and 5 deletions

View file

@ -221,6 +221,9 @@
;; sign ;; sign
(test "+1" (show #f (numeric 1 10 #f #t))) (test "+1" (show #f (numeric 1 10 #f #t)))
(test "+1" (show #f (with ((sign-rule #t)) (numeric 1)))) (test "+1" (show #f (with ((sign-rule #t)) (numeric 1))))
(test "(1)" (show #f (with ((sign-rule '("(" . ")"))) (numeric -1))))
(test "-1" (show #f (with ((sign-rule '("-" . ""))) (numeric -1))))
(test "1" (show #f (with ((sign-rule '("" . ""))) (numeric -1))))
(test "-0.0" (show #f (with ((sign-rule #t)) (numeric -0.0)))) (test "-0.0" (show #f (with ((sign-rule #t)) (numeric -0.0))))
(test "+0.0" (show #f (with ((sign-rule #t)) (numeric +0.0)))) (test "+0.0" (show #f (with ((sign-rule #t)) (numeric +0.0))))

View file

@ -303,11 +303,17 @@
(define (wrap-sign n sign-rule) (define (wrap-sign n sign-rule)
(cond (cond
((negative?* n) ((negative?* n)
(if (char? sign-rule) (cond
(string-append (string sign-rule) ((char? sign-rule)
(wrap-comma (- n)) (string-append (string sign-rule)
(string (char-mirror sign-rule))) (wrap-comma (- n))
(string-append "-" (wrap-comma (- n))))) (string (char-mirror sign-rule))))
((pair? sign-rule)
(string-append (car sign-rule)
(wrap-comma (- n))
(cdr sign-rule)))
(else
(string-append "-" (wrap-comma (- n))))))
((eq? #t sign-rule) ((eq? #t sign-rule)
(string-append "+" (wrap-comma n))) (string-append "+" (wrap-comma n)))
(else (else