mirror of
https://github.com/ashinn/chibi-scheme.git
synced 2025-06-29 17:26:41 +02:00
Fix reversal of results in rounding all leading 9's (issue #859).
This commit is contained in:
parent
fa8a506ed5
commit
1e47c78b8a
2 changed files with 17 additions and 8 deletions
|
@ -210,6 +210,15 @@
|
||||||
(test "1.1" (show #f (numeric #i9/8 10 1)))
|
(test "1.1" (show #f (numeric #i9/8 10 1)))
|
||||||
(test "1" (show #f (numeric #i9/8 10 0)))
|
(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
|
;; precision-show, base-4
|
||||||
(test "1.1230" (show #f (numeric 91/64 4 4)))
|
(test "1.1230" (show #f (numeric 91/64 4 4)))
|
||||||
(test "1.123" (show #f (numeric 91/64 4 3)))
|
(test "1.123" (show #f (numeric 91/64 4 3)))
|
||||||
|
|
|
@ -145,7 +145,7 @@
|
||||||
(let lp ((ls ls) (res '()))
|
(let lp ((ls ls) (res '()))
|
||||||
(cond
|
(cond
|
||||||
((null? ls)
|
((null? ls)
|
||||||
(cons 1 res))
|
(append (reverse res) '(1)))
|
||||||
((not (number? (car ls)))
|
((not (number? (car ls)))
|
||||||
(lp (cdr ls) (cons (car ls) res)))
|
(lp (cdr ls) (cons (car ls) res)))
|
||||||
((= (car ls) (- radix 1))
|
((= (car ls) (- radix 1))
|
||||||
|
@ -203,9 +203,9 @@
|
||||||
(+ i 1)
|
(+ i 1)
|
||||||
(cons q res))))))
|
(cons q res))))))
|
||||||
(else
|
(else
|
||||||
(list->string
|
(reverse-list->string
|
||||||
(map char-digit
|
(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
|
;; Generate a fixed precision decimal result by post-editing the
|
||||||
;; result of string->number.
|
;; result of string->number.
|
||||||
(define (gen-fixed n)
|
(define (gen-fixed n)
|
||||||
|
@ -240,11 +240,11 @@
|
||||||
(string-ref/cursor
|
(string-ref/cursor
|
||||||
s (string-cursor-prev s last)))
|
s (string-cursor-prev s last)))
|
||||||
'(1 3 5 7 9))))))
|
'(1 3 5 7 9))))))
|
||||||
(list->string
|
(reverse-list->string
|
||||||
(reverse
|
(map char-digit
|
||||||
(map char-digit
|
(round-up
|
||||||
(round-up
|
(reverse
|
||||||
(reverse (map digit-value (string->list res)))))))
|
(map digit-value (string->list res))))))
|
||||||
res))))))
|
res))))))
|
||||||
(else
|
(else
|
||||||
(gen-general n))))
|
(gen-general n))))
|
||||||
|
|
Loading…
Add table
Reference in a new issue