Commit aa0a044c authored by Daniel Kochmański's avatar Daniel Kochmański Committed by Daniel Kochmański

format-f: Trailing digit is obligatory unless explicitly set d=0.

CLHS says that if field width is too small and no overflow character
is specified then minimal number of characters necessary to print a
number should be used.

Printing float which characteristic is not zero should print also at
least one digit of mantissa, because without trailing digit if put
back to the reader it would be considered as integer. Exceptional
situation is when mantissa length is explicitly set to zero.

Examples:

    (format nil "~0f"   3.0)   ; correct result is 3.0
    (format nil "~0f"   3.123) ; correct result is 3.1
    (format nil "~0,0f" 3.123) ; correct result is 3.
Signed-off-by: 's avatarDaniel Kochmański <dkochmanski@turtle-solutions.eu>
parent d6735208
......@@ -78,7 +78,7 @@
(loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
for s = (format nil "~2f" x)
for s2 = (formatter-call-to-string fn x)
unless (and (string= s "1.") (string= s s2))
unless (and (string= s "1.0") (string= s s2))
collect (list x s s2)))
nil)
......@@ -105,7 +105,7 @@
(loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
for s = (format nil "~3@F" x)
for s2 = (formatter-call-to-string fn x)
unless (and (string= s "+1.") (string= s s2))
unless (and (string= s "+1.0") (string= s s2))
collect (list x s s2)))
nil)
......@@ -534,3 +534,12 @@
unless (equal s1 s2)
collect (list i c f1 s1 s2))
nil)
(deftest format.f.45
(let ((fn (formatter "~2f")))
(loop for x in (remove-duplicates '(1 1.1s0 1.1f0 1.1d0 1.1l0))
for s = (format nil "~2f" x)
for s2 = (formatter-call-to-string fn x)
unless (and (string= s "1.1") (string= s s2))
collect (list x s s2)))
nil)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment