Tilde-E in absence of format arguments not always same as PRIN1

Bug #2016431 reported by Robert Dodier
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
SBCL
New
Undecided
Unassigned

Bug Description

SBCL version 2.3.3.

`uname -a` reports:
Linux freekbox 4.4.0-148-generic #174~14.04.1-Ubuntu SMP Thu May 9 08:18:11 UTC 2019 i686 i686 i686 GNU/Linux

`*features*`:
```
(:QUICKLISP :ASDF3.3 :ASDF3.2 :ASDF3.1 :ASDF3 :ASDF2 :ASDF :OS-UNIX
 :NON-BASE-CHARS-EXIST-P :ASDF-UNICODE :X86 :GENCGC :ANSI-CL :COMMON-LISP :ELF
 :IEEE-FLOATING-POINT :LINUX :LITTLE-ENDIAN :PACKAGE-LOCAL-NICKNAMES :SB-LDB
 :SB-PACKAGE-LOCKS :SB-THREAD :SB-UNICODE :SBCL :UNIX)
```

CLHS 22.3.3.2 (http://www.lispworks.com/documentation/lw50/CLHS/Body/22_ccb.htm) seems to say that `~e` format in the absence of format arguments produces the same thing as PRIN1 for arguments in the range 0.001 to 1e7.

I've found some examples where `~e` produces a different results as shown here.

```
(defun foo (x)
  (let ((*print-readably* t))
    (let*
      ((a (prin1-to-string x))
       (b (format nil "~e" x))
       (c (read-from-string b)))
      (print (list x a b (- c x))))))

(dotimes (i 20) (foo (* pi (expt 2 (- i 10)))))
```

Here is the output. `(* pi 4)` is the example of smallest magnitude which I found.

```
(0.0030679615757712823 #A((21) BASE-CHAR . "0.0030679615757712823") #A((21) BASE-CHAR . "3.0679615757712825e-3") 0.0)
(0.006135923151542565 #A((20) BASE-CHAR . "0.006135923151542565") #A((20) BASE-CHAR . "6.135923151542565e-3") 0.0)
(0.01227184630308513 #A((19) BASE-CHAR . "0.01227184630308513") #A((20) BASE-CHAR . "1.227184630308513e-2") 0.0)
(0.02454369260617026 #A((19) BASE-CHAR . "0.02454369260617026") #A((20) BASE-CHAR . "2.454369260617026e-2") 0.0)
(0.04908738521234052 #A((19) BASE-CHAR . "0.04908738521234052") #A((20) BASE-CHAR . "4.908738521234052e-2") 0.0)
(0.09817477042468103 #A((19) BASE-CHAR . "0.09817477042468103") #A((20) BASE-CHAR . "9.817477042468103e-2") 0.0)
(0.19634954084936207 #A((19) BASE-CHAR . "0.19634954084936207") #A((21) BASE-CHAR . "1.9634954084936207e-1") 0.0)
(0.39269908169872414 #A((19) BASE-CHAR . "0.39269908169872414") #A((21) BASE-CHAR . "3.9269908169872414e-1") 0.0)
(0.7853981633974483 #A((18) BASE-CHAR . "0.7853981633974483") #A((20) BASE-CHAR . "7.853981633974483e-1") 0.0)
(1.5707963267948966 #A((18) BASE-CHAR . "1.5707963267948966") #A((21) BASE-CHAR . "1.5707963267948966e+0") 0.0)
(3.141592653589793 #A((17) BASE-CHAR . "3.141592653589793") #A((20) BASE-CHAR . "3.141592653589793e+0") 0.0)
(6.283185307179586 #A((17) BASE-CHAR . "6.283185307179586") #A((20) BASE-CHAR . "6.283185307179586e+0") 0.0)
(12.566370614359172 #A((18) BASE-CHAR . "12.566370614359172") #A((21) BASE-CHAR . "1.2566370614359174e+1") 1.7763568394002505e-15)
(25.132741228718345 #A((18) BASE-CHAR . "25.132741228718345") #A((21) BASE-CHAR . "2.5132741228718347e+1") 3.552713678800501e-15)
(50.26548245743669 #A((17) BASE-CHAR . "50.26548245743669") #A((20) BASE-CHAR . "5.026548245743669e+1") 0.0)
(100.53096491487338 #A((18) BASE-CHAR . "100.53096491487338") #A((21) BASE-CHAR . "1.0053096491487339e+2") 1.4210854715202004e-14)
(201.06192982974676 #A((18) BASE-CHAR . "201.06192982974676") #A((21) BASE-CHAR . "2.0106192982974677e+2") 0.0)
(402.1238596594935 #A((17) BASE-CHAR . "402.1238596594935") #A((21) BASE-CHAR . "4.0212385965949354e+2") 0.0)
(804.247719318987 #A((16) BASE-CHAR . "804.247719318987") #A((20) BASE-CHAR . "8.042477193189871e+2") 1.1368683772161603e-13)
(1608.495438637974 #A((17) BASE-CHAR . "1608.495438637974") #A((20) BASE-CHAR . "1.608495438637974e+3") 0.0)
NIL
```

Incidentally `~f` doesn't have the same behavior -- I didn't find any examples in which `~f` output in the absence of format arguments produces a results different from PRIN1.

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.