ANSI-TEST FORMAT.E.1 fails - FORMAT ~E is inconsistent with PRIN1
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
SBCL |
New
|
Undecided
|
Unassigned |
Bug Description
CLHS 22.1.3.1.3 states that FORMAT ~E is equivalent to PRIN1 for (abs x) outside of the range [10^-3,10^7), apart from the sign of the exponent, which is always printed. This is always not the case on SBCL, as there are rounding differences between PRIN1 and FORMAT ~E.
The test body from ANSI-TEST FORMAT.E.1 that triggers this behaviour:
https:/
Extracted test body to run on SBCL without ANSI-TEST loaded:
(defmacro formatter-
(let ((stream (gensym "S")))
`(with-
(assert (equal (funcall ,fn ,stream ,@args 'a) '(a))))))
(let ((*print-readably* nil)
(fn (formatter "~e")))
(loop
for i = (random 4)
for type = (elt #(short-float single-float double-float long-float)
for min-value = (elt (vector least-positive-
for max-value = (elt (vector most-positive-
for x = (expt (coerce 10 type)
for s1 = (let ((*read-
for s2 = (let* ((*read-
(if (> x 1)
for s3 = (let ((*read-
repeat 1000
when (and (or (< x 1/1000)
(or (not (string= s1 s2))
collect (list x s1 s2 s3)))
Some examples of the inconsistency returned by the above test:
(4.181094272874
(2.921563131353
(6.893129496037
(4.028950514066
(4.9146875e-20 "4.9146876e-20" "4.9146875e-20" "4.9146876e-20")
More rationale from CLHS 22.3.3.2:
If all of w, d, and e are omitted, then the effect is to print the value using ordinary free-format exponential- notation output; prin1 uses a similar format for any non-zero number whose magnitude is less than 10^-3 or greater than or equal to 10^7. The only difference is that the ~E directive always prints a plus or minus sign in front of the exponent, while prin1 omits the plus sign if the exponent is non-negative.