Skip to content
Snippets Groups Projects
Commit 9e71e519 authored by rtoy's avatar rtoy
Browse files

o Incorrect number of digits were printed for ~wF.

o If FMIN is given, print out the digits, even if we're out of room.
  (This is so ~E will print at least 1 digit due to a bad choice in
  scale factor.)

The following tests all pass.

(assert (string= (format nil "~9,3,2,0,'%G" 0.0314159) "0.314e-01"))
(assert (string= (format nil "~9,3,2,-2,'%@e" 3.14159) "+.003e+03"))
(assert (string= (format nil "~6,2,1,'*F" 3.14159) " 31.42"))
(assert (string= (format nil "~9,0,6f" 3.14159) " 3141590."))

(assert (string= (format nil "~9,4,,-7E" pi) ".00000003d+8"))
(assert (string= (format nil "~9,4,,-5E" pi) ".000003d+6"))
(assert (string= (format nil "~5,4,,7E" pi) "3141600.d-6"))
(assert (string= (format nil "~11,4,,3E" pi) "  314.16d-2"))
(assert (string= (format nil "~11,4,,5E" pi) "  31416.d-4"))
(assert (string= (format nil "~11,4,,0E" pi) "  0.3142d+1"))
(assert (string= (format nil "~9,,,-1E" pi) ".03142d+2"))
(assert (string= (format nil "~,,,-2E" pi) "0.003141592653589793d+3"))
(assert (string= (format nil "~,,,2E" pi) "31.41592653589793d-1"))
(assert (string= (format nil "~E" pi) "3.141592653589793d+0"))
(assert (string= (format nil "~9,5,,-1E" pi) ".03142d+2"))
(assert (string= (format nil "~11,5,,-1E" pi) " 0.03142d+2"))
(assert (string= (format nil "~G" pi) "3.141592653589793    "))
(assert (string= (format nil "~9,5G" pi) "3.1416    "))
(assert (string= (format nil "|~13,6,2,7E|" pi) "| 3141593.d-06|"))
(assert (string= (format nil "~9,3,2,0,'%E" pi) "0.314d+01"))
(assert (string= (format nil "~9,0,6f" pi) " 3141593."))
(assert (string= (format nil "~6,2,1,'*F" pi) " 31.42"))
(assert (string= (format nil "~6,2,1,'*F" (* 100 pi)) "******"))
(assert (string= (format nil "~9,3,2,-2,'%@E" pi) "+.003d+03"))
(assert (string= (format nil "~10,3,2,-2,'%@E" pi) "+0.003d+03"))
(assert (string= (format nil "~15,3,2,-2,'%,'=@E" pi) "=====+0.003d+03"))
(assert (string= (format nil "~9,3,2,-2,'%E" pi) "0.003d+03"))
(assert (string= (format nil "~8,3,2,-2,'%@E" pi) "%%%%%%%%"))

(assert (string= (format nil "~g" 1e0) "1.    "))
;(assert (string= (format nil "~g" 1.2d40) "12000000000000000000000000000000000000000.    "))

(assert (string= (format nil "~e" 0) "0.0e+0"))
(assert (string= (format nil "~e" 0d0) "0.0d+0"))
(assert (string= (format nil "~9,,4e" 0d0) "0.0d+0000"))
(assert (string= (format nil "~E" 1.234567890123456789d4) "1.2345678901234567d+4"))

(assert (string= (format nil "~20E" (expt 2d0 120)) "1.32922799578492d+36"))
(assert (string= (format nil "~21,8E" (expt 2d0 120)) "       1.32922800d+36"))

(assert (string= (format nil "~11f" 1.23456789123456789d-3) ".0012345679"))

;; From CLH 22.3.11
(defun test-f (x)
   (format nil "~6,2F|~6,2,1,'*F|~6,2,,'?F|~6F|~,2F|~F"
           x x x x x x))

(assert (string= (test-f 3.14159) "  3.14| 31.42|  3.14|3.1416|3.14|3.14159"))
(assert (string= (test-f -3.14159) " -3.14|-31.42| -3.14|-3.142|-3.14|-3.14159" ))
(assert (string= (test-f 100.0)  "100.00|******|100.00| 100.0|100.00|100.0"))
(assert (string= (test-f 1234.0) "1234.00|******|??????|1234.0|1234.00|1234.0"))
(assert (string= (test-f 0.006) "  0.01|  0.06|  0.01| 0.006|0.01|0.006"))



(defun test-e (x)
    (format nil
           "~9,2,1,,'*E|~10,3,2,2,'?,,'$E|~
            ~9,3,2,-2,'%@E|~9,2E"
           x x x x))


(assert (string= (test-e 3.14159)  "  3.14e+0| 31.42$-01|+.003e+03|  3.14e+0"))
(assert (string= (test-e -3.14159)  " -3.14e+0|-31.42$-01|-.003e+03| -3.14e+0"))
(assert (string= (test-e 1100.0)  "  1.10e+3| 11.00$+02|+.001e+06|  1.10e+3"))
(assert (string= (test-e 1100.0d0)  "  1.10d+3| 11.00$+02|+.001d+06|  1.10d+3"))
(assert (string= (test-e 1.1e13)  "*********| 11.00$+12|+.001e+16| 1.10e+13"))
(assert (string= (test-e 1.1d120)  "*********|??????????|%%%%%%%%%|1.10d+120"))

(defun test-scale (k)
  (format nil "~&Scale factor ~2D: |~13,6,2,VE|"
	  (- k 5) (- k 5) 3.14159))

(assert (string= (test-scale 0) "Scale factor -5: | 0.000003e+06|"))
(assert (string= (test-scale 1) "Scale factor -4: | 0.000031e+05|"))
(assert (string= (test-scale 2) "Scale factor -3: | 0.000314e+04|"))
(assert (string= (test-scale 3) "Scale factor -2: | 0.003142e+03|"))
(assert (string= (test-scale 4) "Scale factor -1: | 0.031416e+02|"))
(assert (string= (test-scale 5) "Scale factor  0: | 0.314159e+01|"))
(assert (string= (test-scale 6) "Scale factor  1: | 3.141590e+00|"))
(assert (string= (test-scale 7) "Scale factor  2: | 31.41590e-01|"))
(assert (string= (test-scale 8) "Scale factor  3: | 314.1590e-02|"))
(assert (string= (test-scale 9) "Scale factor  4: | 3141.590e-03|"))
(assert (string= (test-scale 10) "Scale factor  5: | 31415.90e-04|"))
(assert (string= (test-scale 11) "Scale factor  6: | 314159.0e-05|"))
(assert (string= (test-scale 12) "Scale factor  7: | 3141590.e-06|"))
parent 9877b8f6
No related branches found
No related tags found
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment