| ... |
... |
@@ -367,18 +367,21 @@ |
|
367
|
367
|
(assert-equal " 1.0"
|
|
368
|
368
|
(lisp::format-f 1d0 10 nil 0 nil nil nil)))
|
|
369
|
369
|
|
|
370
|
|
-(define-test format-f.d-nil-with-w-shrinks
|
|
|
370
|
+(define-test format-f.d-nil-with-w-no-shrink
|
|
371
|
371
|
(:tag :format-f)
|
|
372
|
|
- ;; d=nil with tight width: must shrink fractional digits via d2fixed.
|
|
373
|
|
- ;; 3.141592653589793 has 16 fractional digits at shortest; w=8 only
|
|
374
|
|
- ;; allows 6 (sign 0 + int 1 + dot 1 + frac 6 = 8).
|
|
375
|
|
- (assert-equal "3.141593"
|
|
376
|
|
- (lisp::format-f 3.141592653589793d0 8 nil 0 nil nil nil))
|
|
377
|
|
- (assert-equal "3.14159265"
|
|
|
372
|
+ ;; CLHS 22.3.3.1: when d is unspecified, the digit count is set so
|
|
|
373
|
+ ;; that the result reads back as an EQUAL float, with no extraneous
|
|
|
374
|
+ ;; trailing zeros. This is the round-trip count. When the result
|
|
|
375
|
+ ;; does not fit in w and no overflowchar is supplied, the field
|
|
|
376
|
+ ;; expands -- it does NOT shrink the digits, because doing so would
|
|
|
377
|
+ ;; produce a different float on read-back. (Earlier ryu code did
|
|
|
378
|
+ ;; shrink here; that change was needed to pass ANSI FORMAT.F.5.)
|
|
|
379
|
+ (assert-equal "1.234567"
|
|
|
380
|
+ (lisp::format-f 1.234567d0 6 nil 0 nil nil nil))
|
|
|
381
|
+ (assert-equal "3.141592653589793"
|
|
378
|
382
|
(lisp::format-f 3.141592653589793d0 10 nil 0 nil nil nil))
|
|
379
|
|
- ;; The shrink should round correctly: 5 with following digits rounds up.
|
|
380
|
|
- (assert-equal "1.2346"
|
|
381
|
|
- (lisp::format-f 1.234567d0 6 nil 0 nil nil nil)))
|
|
|
383
|
+ (assert-equal "3.141592653589793"
|
|
|
384
|
+ (lisp::format-f 3.141592653589793d0 8 nil 0 nil nil nil)))
|
|
382
|
385
|
|
|
383
|
386
|
(define-test format-f.d-nil-with-w-overflow
|
|
384
|
387
|
(:tag :format-f)
|