diff --git a/lib/srfi/166/test.sld b/lib/srfi/166/test.sld index a6a2f9c1..438f80af 100644 --- a/lib/srfi/166/test.sld +++ b/lib/srfi/166/test.sld @@ -210,6 +210,15 @@ (test "1.1" (show #f (numeric #i9/8 10 1))) (test "1" (show #f (numeric #i9/8 10 0))) + (test "1.0" + (show #f (with ((precision 1)) 0.999999999999876))) + (test "10.0" + (show #f (with ((precision 1)) 9.999999999999876))) + (test "10.0" + (show #f (numeric 9.999999999999876 10 1))) + (test "10.00" + (show #f (numeric 9.999999999999876 10 2))) + ;; precision-show, base-4 (test "1.1230" (show #f (numeric 91/64 4 4))) (test "1.123" (show #f (numeric 91/64 4 3))) diff --git a/lib/srfi/166/write.scm b/lib/srfi/166/write.scm index 0bdfb3d8..a185ec92 100644 --- a/lib/srfi/166/write.scm +++ b/lib/srfi/166/write.scm @@ -145,7 +145,7 @@ (let lp ((ls ls) (res '())) (cond ((null? ls) - (cons 1 res)) + (append (reverse res) '(1))) ((not (number? (car ls))) (lp (cdr ls) (cons (car ls) res))) ((= (car ls) (- radix 1)) @@ -203,9 +203,9 @@ (+ i 1) (cons q res)))))) (else - (list->string + (reverse-list->string (map char-digit - (reverse (maybe-trim-zeros i (maybe-round n d res) (inexact? n-orig)))))))))) + (maybe-trim-zeros i (maybe-round n d res) (inexact? n-orig))))))))) ;; Generate a fixed precision decimal result by post-editing the ;; result of string->number. (define (gen-fixed n) @@ -240,11 +240,11 @@ (string-ref/cursor s (string-cursor-prev s last))) '(1 3 5 7 9)))))) - (list->string - (reverse - (map char-digit - (round-up - (reverse (map digit-value (string->list res))))))) + (reverse-list->string + (map char-digit + (round-up + (reverse + (map digit-value (string->list res)))))) res)))))) (else (gen-general n))))