/[gcl]/gcl/ansi-tests/format-f.lsp
ViewVC logotype

Diff of /gcl/ansi-tests/format-f.lsp

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.5 by pfdietz, Sat Nov 27 19:36:18 2004 UTC revision 1.6 by pfdietz, Wed Dec 8 12:47:21 2004 UTC
# Line 10  Line 10 
10  ;;; Equivalent to PRIN1 for 0 or (abs x) in range [10^-3,10^7).  ;;; Equivalent to PRIN1 for 0 or (abs x) in range [10^-3,10^7).
11    
12  (deftest format.f.1  (deftest format.f.1
13    (let ((*print-readably* nil))    (let ((*print-readably* nil)
14            (fn (formatter "~F")))
15      (loop      (loop
16       for type in '(short-float single-float double-float long-float       for type in '(short-float single-float double-float long-float
17                     short-float single-float double-float long-float)                     short-float single-float double-float long-float)
# Line 18  Line 19 
19                        -0.0s0 -0.0f0 -0.0d0 -0.0l0)                        -0.0s0 -0.0f0 -0.0d0 -0.0l0)
20       for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))       for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))
21       for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))       for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))
22       unless (string=t s1 s2)       for s3 = (let ((*read-default-float-format* type))
23       collect (list x type s1 s2)))                  (formatter-call-to-string fn x))
24         unless (and (string= s1 s2) (string= s1 s3))
25         collect (list x type s1 s2 s3)))
26    nil)    nil)
27    
28  (deftest format.f.2  (deftest format.f.2
29    (let ((*print-readably* nil))    (let ((*print-readably* nil)
30            (fn (formatter "~f")))
31      (loop      (loop
32       for i = (random 4)       for i = (random 4)
33       for type = (elt #(short-float single-float double-float long-float) i)       for type = (elt #(short-float single-float double-float long-float) i)
# Line 31  Line 35 
35                     (- (random 10.0s0) 3))                     (- (random 10.0s0) 3))
36       for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))       for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))
37       for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))       for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))
38         for s3 = (let ((*read-default-float-format* type))
39                    (formatter-call-to-string fn x))
40       repeat 1000       repeat 1000
41       when (and (<= 1/1000 x)       when (and (<= 1/1000 x)
42                 (< x 10000000)                 (< x 10000000)
43                 (not (string= s1 s2)))                 (or (not (string= s1 s2))
44       collect (list x s1 s2)))                     (not (string= s1 s3))))
45         collect (list x s1 s2 s3)))
46    nil)    nil)
47    
48  (deftest format.f.3  (deftest format.f.3
49    (let ((*print-readably* nil))    (let ((*print-readably* nil)
50            (fn (formatter "~F")))
51      (loop      (loop
52       for i = (random 4)       for i = (random 4)
53       for type = (elt #(short-float single-float double-float long-float) i)       for type = (elt #(short-float single-float double-float long-float) i)
# Line 47  Line 55 
55                        (- (random 10.0s0) 3)))                        (- (random 10.0s0) 3)))
56       for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))       for s1 = (let ((*read-default-float-format* type)) (format nil "~f" x))
57       for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))       for s2 = (let ((*read-default-float-format* type)) (prin1-to-string x))
58         for s3 = (let ((*read-default-float-format* type))
59                    (formatter-call-to-string fn x))
60       repeat 1000       repeat 1000
61       when (and (>= -1/1000 x)       when (and (>= -1/1000 x)
62                 (> x -10000000)                 (> x -10000000)
63                 (not (string= s1 s2)))                 (not (and (string= s1 s2) (string= s1 s3))))
64       collect (list x s1 s2)))       collect (list x s1 s2 s3)))
65    nil)    nil)
66    
67  (deftest format.f.4  (deftest format.f.4
68    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))    (let ((fn (formatter "~3f")))
69          for s = (format nil "~3f" x)      (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
70          unless (string= s "1.0")            for s = (format nil "~3f" x)
71          collect (list x s))            for s2 = (formatter-call-to-string fn x)
72              unless (and (string= s "1.0") (string= s s2))
73              collect (list x s s2)))
74    nil)    nil)
75    
76  (deftest format.f.5  (deftest format.f.5
77    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))    (let ((fn (formatter "~2f")))
78          for s = (format nil "~2f" x)      (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
79          unless (string= s "1.")            for s = (format nil "~2f" x)
80          collect (list x s))            for s2 = (formatter-call-to-string fn x)
81              unless (and (string= s "1.") (string= s s2))
82              collect (list x s s2)))
83    nil)    nil)
84    
85  (deftest format.f.6  (deftest format.f.6
86    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))    (let ((fn (formatter "~4F")))
87          for s = (format nil "~4F" x)      (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
88          unless (string= s " 1.0")            for s = (format nil "~4F" x)
89          collect (list x s))            for s2 = (formatter-call-to-string fn x)
90              unless (and (string= s " 1.0") (string= s s2))
91              collect (list x s s2)))
92    nil)    nil)
93    
94  (deftest format.f.7  (deftest format.f.7
95    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))    (let ((fn (formatter "~4@F")))
96          for s = (format nil "~4@f" x)      (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
97          unless (string= s "+1.0")            for s = (format nil "~4@f" x)
98          collect (list x s))            for s2 = (formatter-call-to-string fn x)
99              unless (and (string= s "+1.0") (string= s s2))
100              collect (list x s s2)))
101    nil)    nil)
102    
103  (deftest format.f.8  (deftest format.f.8
104    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))    (let ((fn (formatter "~3@F")))
105          for s = (format nil "~3@F" x)      (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
106          unless (string= s "+1.")            for s = (format nil "~3@F" x)
107          collect (list x s))            for s2 = (formatter-call-to-string fn x)
108              unless (and (string= s "+1.") (string= s s2))
109              collect (list x s s2)))
110    nil)    nil)
111    
112  (deftest format.f.9  (deftest format.f.9
113    (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))    (let ((fn (formatter "~4f")))
114          for s = (format nil "~4f" (- x))      (loop for x in (remove-duplicates '(1 1.0s0 1.0f0 1.0d0 1.0l0))
115          unless (string= s "-1.0")            for s = (format nil "~4f" (- x))
116          collect (list (- x) s))            for s2 = (formatter-call-to-string fn (- x))
117              unless (and (string= s "-1.0") (string= s s2))
118              collect (list (- x) s s2)))
119    nil)    nil)
120    
121  (deftest format.f.10  (deftest format.f.10
122    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~3F")))
123          for s = (format nil "~3f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
124          unless (string= s "0.5")            for s = (format nil "~3f" x)
125          collect (list x s))            for s2 = (formatter-call-to-string fn x)
126              unless (and (string= s "0.5") (string= s s2))
127              collect (list x s s2)))
128    nil)    nil)
129    
130  (deftest format.f.11  (deftest format.f.11
131    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~4f")))
132          for s = (format nil "~4f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
133          unless (string= s " 0.5")            for s = (format nil "~4f" x)
134          collect (list x s))            for s2 = (formatter-call-to-string fn x)
135              unless (and (string= s " 0.5") (string= s s2))
136              collect (list x s s2)))
137    nil)    nil)
138    
139  (deftest format.f.12  (deftest format.f.12
140    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~4,2F")))
141          for s = (format nil "~4,2f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
142          unless (string= s "0.50")            for s = (format nil "~4,2f" x)
143          collect (list x s))            for s2 = (formatter-call-to-string fn x)
144              unless (and (string= s "0.50") (string= s s2))
145              collect (list x s s2)))
146    nil)    nil)
147    
148  (deftest format.f.13  (deftest format.f.13
149    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~3,2F")))
150          for s = (format nil "~3,2f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
151          unless (string= s ".50")            for s = (format nil "~3,2f" x)
152          collect (list x s))            for s2 = (formatter-call-to-string fn x)
153              unless (and (string= s ".50") (string= s s2))
154              collect (list x s s2)))
155    nil)    nil)
156    
157  (deftest format.f.14  (deftest format.f.14
158    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~2,1F")))
159          for s = (format nil "~2,1f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
160          unless (string= s ".5")            for s = (format nil "~2,1f" x)
161          collect (list x s))            for s2 = (formatter-call-to-string fn x)
162              unless (and (string= s ".5") (string= s s2))
163              collect (list x s s2)))
164    nil)    nil)
165    
166  (deftest format.f.15  (deftest format.f.15
167    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~4,2@F")))
168          for s = (format nil "~4,2@f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
169          unless (string= s "+.50")            for s = (format nil "~4,2@f" x)
170          collect (list x s))            for s2 = (formatter-call-to-string fn x)
171              unless (and (string= s "+.50") (string= s s2))
172              collect (list x s s2)))
173    nil)    nil)
174    
175  (deftest format.f.16  (deftest format.f.16
176    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~2,2F")))
177          for s = (format nil "~2,2f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
178          unless (string= s ".50")            for s = (format nil "~2,2f" x)
179          collect (list x s))            for s2 = (formatter-call-to-string fn x)
180              unless (and (string= s ".50") (string= s s2))
181              collect (list x s s2)))
182    nil)    nil)
183    
184  (deftest format.f.17  (deftest format.f.17
185    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~,2F")))
186          for s = (format nil "~,2f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
187          unless (string= s "0.50")            for s = (format nil "~,2f" x)
188          collect (list x s))            for s2 = (formatter-call-to-string fn x)
189              unless (and (string= s "0.50") (string= s s2))
190              collect (list x s s2)))
191    nil)    nil)
192    
193  (deftest format.f.18  (deftest format.f.18
194    (loop for xn in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~,2F")))
195          for x = (- xn)      (loop for xn in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
196          for s = (format nil "~,2f" x)            for x = (- xn)
197          unless (string= s "-0.50")            for s = (format nil "~,2f" x)
198          collect (list x s))            for s2 = (formatter-call-to-string fn x)
199              unless (and (string= s "-0.50") (string= s s2))
200              collect (list x s s2)))
201    nil)    nil)
202    
203  (deftest format.f.19  (deftest format.f.19
204    (loop for x in (remove-duplicates '(5 5.0s0 5.0f0 5.0d0 5.0l0))    (let ((fn (formatter "~4,2,-1F")))
205          for s = (format nil "~4,2,-1f" x)      (loop for x in (remove-duplicates '(5 5.0s0 5.0f0 5.0d0 5.0l0))
206          unless (string= s "0.50")            for s = (format nil "~4,2,-1f" x)
207          collect (list x s))            for s2 = (formatter-call-to-string fn x)
208              unless (and (string= s "0.50") (string= s s2))
209              collect (list x s s2)))
210    nil)    nil)
211    
212  (deftest format.f.20  (deftest format.f.20
213    (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))    (let ((fn (formatter "~4,2,0F")))
214          for s = (format nil "~4,2,0f" x)      (loop for x in (remove-duplicates '(1/2 0.5s0 0.5f0 0.5d0 0.5l0))
215          unless (string= s "0.50")            for s = (format nil "~4,2,0f" x)
216          collect (list x s))            for s2 = (formatter-call-to-string fn x)
217              unless (and (string= s "0.50") (string= s s2))
218              collect (list x s s2)))
219    nil)    nil)
220    
221  (deftest format.f.21  (deftest format.f.21
222    (loop for x in (remove-duplicates '(1/20 0.05s0 0.05f0 0.05d0 0.05l0))    (let ((fn (formatter "~4,2,1f")))
223          for s = (format nil "~4,2,1f" x)      (loop for x in (remove-duplicates '(1/20 0.05s0 0.05f0 0.05d0 0.05l0))
224          unless (string= s "0.50")            for s = (format nil "~4,2,1f" x)
225          collect (list x s))            for s2 = (formatter-call-to-string fn x)
226              unless (and (string= s "0.50") (string= s s2))
227              collect (list x s s2)))
228    nil)    nil)
229    
230  ;;; overflow  ;;; overflow
231    
232  (deftest format.f.22  (deftest format.f.22
233    (loop for x in (remove-duplicates    (let ((fn (formatter "~5,1,,'*F")))
234                    '(1000 1000.0s0 1000.0f0 1000.0d0 1000.0l0))      (loop for x in (remove-duplicates
235          for s = (format nil "~5,1,,'*f" x)                      '(1000 1000.0s0 1000.0f0 1000.0d0 1000.0l0))
236          unless (string= s "*****")            for s = (format nil "~5,1,,'*f" x)
237          collect (list x s))            for s2 = (formatter-call-to-string fn x)
238              unless (and (string= s "*****") (string= s s2))
239              collect (list x s s2)))
240    nil)    nil)
241    
242  (deftest format.f.23  (deftest format.f.23
243    (loop for x in (remove-duplicates    (let ((fn (formatter "~5,1,,'*f")))
244                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))      (loop for x in (remove-duplicates
245          for s = (format nil "~5,1,,'*f" x)                      '(100 100.0s0 100.0f0 100.0d0 100.0l0))
246          unless (string= s "100.0")            for s = (format nil "~5,1,,'*f" x)
247          collect (list x s))            for s2 = (formatter-call-to-string fn x)
248              unless (and (string= s "100.0") (string= s s2))
249              collect (list x s s2)))
250    nil)    nil)
251    
252  (deftest format.f.24  (deftest format.f.24
253    (loop for x in (remove-duplicates    (let ((fn (formatter "~4,0,,'*F")))
254                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))      (loop for x in (remove-duplicates
255          for s = (format nil "~4,0,,'*f" x)                      '(100 100.0s0 100.0f0 100.0d0 100.0l0))
256          unless (string= s "100.")            for s = (format nil "~4,0,,'*f" x)
257          collect (list x s))            for s2 = (formatter-call-to-string fn x)
258              unless (and (string= s "100.") (string= s s2))
259              collect (list x s s2)))
260    nil)    nil)
261    
262  (deftest format.f.25  (deftest format.f.25
263    (loop for x in (remove-duplicates    (let ((fn (formatter "~1,1,,f")))
264                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))      (loop for x in (remove-duplicates
265          for s = (format nil "~1,1,,f" x)                      '(100 100.0s0 100.0f0 100.0d0 100.0l0))
266          unless (string= s "100.0")            for s = (format nil "~1,1,,f" x)
267          collect (list x s))            for s2 = (formatter-call-to-string fn x)
268              unless (and (string= s "100.0") (string= s s2))
269              collect (list x s s2)))
270    nil)    nil)
271    
272  ;;; padchar  ;;; padchar
273    
274  (deftest format.f.26  (deftest format.f.26
275    (loop for x in (remove-duplicates    (let ((fn (formatter "~10,1,,f")))
276                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))      (loop for x in (remove-duplicates
277          for s = (format nil "~10,1,,f" x)                      '(100 100.0s0 100.0f0 100.0d0 100.0l0))
278          unless (string= s "     100.0")            for s = (format nil "~10,1,,f" x)
279          collect (list x s))            for s2 = (formatter-call-to-string fn x)
280              unless (and (string= s "     100.0") (string= s s2))
281              collect (list x s s2)))
282    nil)    nil)
283    
284  (deftest format.f.27  (deftest format.f.27
285    (loop for x in (remove-duplicates    (let ((fn (formatter "~10,1,,,'*F")))
286                    '(100 100.0s0 100.0f0 100.0d0 100.0l0))      (loop for x in (remove-duplicates
287          for s = (format nil "~10,1,,,'*f" x)                      '(100 100.0s0 100.0f0 100.0d0 100.0l0))
288          unless (string= s "*****100.0")            for s = (format nil "~10,1,,,'*f" x)
289          collect (list x s))            for s2 = (formatter-call-to-string fn x)
290              unless (and (string= s "*****100.0") (string= s s2))
291              collect (list x s s2)))
292    nil)    nil)
293    
294  ;;; v parameters  ;;; v parameters
295    
296  (deftest format.f.28  (deftest format.f.28
297    (loop for x = (random 100.0)    (let ((fn (formatter "~VF")))
298          for s1 = (format nil "~f" x)      (loop for x = (random 100.0)
299          for s2 = (format nil "~vf" nil x)            for s1 = (format nil "~f" x)
300          repeat 100            for s2 = (format nil "~vf" nil x)
301          unless (string= s1 s2)            for s3 = (formatter-call-to-string fn nil x)
302          collect (list x s1 s2))            repeat 100
303              unless (and (string= s1 s2) (string= s2 s3))
304              collect (list x s1 s2 s3)))
305    nil)    nil)
306    
307  (deftest format.f.29  (deftest format.f.29
308    (loop for x = (random 100.0)    (let ((fn (formatter "~,vf")))
309          for s1 = (format nil "~f" x)      (loop for x = (random 100.0)
310          for s2 = (format nil "~,vf" nil x)            for s1 = (format nil "~f" x)
311          repeat 100            for s2 = (format nil "~,vf" nil x)
312          unless (string= s1 s2)            for s3 = (formatter-call-to-string fn nil x)
313          collect (list x s1 s2))            repeat 100
314              unless (and (string= s1 s2) (string= s2 s3))
315              collect (list x s1 s2 s3)))
316    nil)    nil)
317    
318  (deftest format.f.30  (deftest format.f.30
319    (loop for x = (random 100.0)    (let ((fn (formatter "~,,Vf")))
320          for s1 = (format nil "~f" x)      (loop for x = (random 100.0)
321          for s2 = (format nil "~,,vf" nil x)            for s1 = (format nil "~f" x)
322          repeat 100            for s2 = (format nil "~,,vf" nil x)
323          unless (string= s1 s2)            for s3 = (formatter-call-to-string fn nil x)
324          collect (list x s1 s2))            repeat 100
325              unless (and (string= s1 s2) (string= s2 s3))
326              collect (list x s1 s2 s3)))
327    nil)    nil)
328    
329  (deftest format.f.31  (deftest format.f.31
330    (loop for x = (random 100.0)    (let ((fn (formatter "~,,,vF")))
331          for s1 = (format nil "~f" x)      (loop for x = (random 100.0)
332          for s2 = (format nil "~,,,vf" nil x)            for s1 = (format nil "~f" x)
333          repeat 100            for s2 = (format nil "~,,,vf" nil x)
334          unless (string= s1 s2)            for s3 = (formatter-call-to-string fn nil x)
335          collect (list x s1 s2))            repeat 100
336              unless (and (string= s1 s2) (string= s2 s3))
337              collect (list x s1 s2 s3)))
338    nil)    nil)
339    
340  (deftest format.f.32  (deftest format.f.32
341    (loop for x = (random 100.0)    (let ((fn (formatter "~,,,,VF")))
342          for s1 = (format nil "~f" x)      (loop for x = (random 100.0)
343          for s2 = (format nil "~,,,,vf" nil x)            for s1 = (format nil "~f" x)
344          repeat 100            for s2 = (format nil "~,,,,vf" nil x)
345          unless (string= s1 s2)            for s3 = (formatter-call-to-string fn nil x)
346          collect (list x s1 s2))            repeat 100
347              unless (and (string= s1 s2) (string= s2 s3))
348              collect (list x s1 s2 s3)))
349    nil)    nil)
350    
351  ;;; Randomized tests  ;;; Randomized tests

Legend:
Removed from v.1.5  
changed lines
  Added in v.1.6

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26