source: trunk/source/tests/ansi-tests/expt.lsp @ 8991

Last change on this file since 8991 was 8991, checked in by gz, 11 years ago

Check in the gcl ansi test suite (original, in preparation for making local changes)

File size: 4.9 KB
Line 
1;-*- Mode:     Lisp -*-
2;;;; Author:   Paul Dietz
3;;;; Created:  Tue Sep  2 19:36:22 2003
4;;;; Contains: Tests of EXPT
5
6(in-package :cl-test)
7
8;;; Error tests
9
10(deftest expt.error.1
11  (signals-error (expt) program-error)
12  t)
13
14(deftest expt.error.2
15  (signals-error (expt 1 1 1) program-error)
16  t)
17
18(deftest expt.error.3
19  (signals-error (expt 1 1 nil nil) program-error)
20  t)
21
22(deftest expt.error.4
23  (signals-error (expt most-positive-short-float 2) floating-point-overflow)
24  t)
25
26(deftest expt.error.5
27  (signals-error (expt most-positive-single-float 2) floating-point-overflow)
28  t)
29
30(deftest expt.error.6
31  (signals-error (expt most-positive-double-float 2) floating-point-overflow)
32  t)
33
34(deftest expt.error.7
35  (signals-error (expt most-positive-long-float 2) floating-point-overflow)
36  t)
37
38(deftest expt.error.8
39  (signals-error (expt least-positive-short-float 2) floating-point-underflow)
40  t)
41
42(deftest expt.error.9
43  (signals-error (expt least-positive-single-float 2) floating-point-underflow)
44  t)
45
46(deftest expt.error.10
47  (signals-error (expt least-positive-double-float 2) floating-point-underflow)
48  t)
49
50(deftest expt.error.11
51  (signals-error (expt least-positive-long-float 2) floating-point-underflow)
52  t)
53
54
55
56
57;;; Non-error tests
58
59(deftest expt.1
60  (expt 0 0)
61  1)
62
63(deftest expt.2
64  (loop for i from -1000 to 1000
65        always (eql (expt i 0) 1))
66  t)
67
68(deftest expt.3
69  (loop for i = (random 1.0s3)
70        repeat 1000
71        always (eql (expt i 0) 1.0s0))
72  t)
73
74(deftest expt.4
75  (loop for i = (random 1.0f6)
76        repeat 1000
77        always (eql (expt i 0) 1.0f0))
78  t)
79
80(deftest expt.5
81  (loop for i = (random 1.0d10)
82        repeat 1000
83        always (eql (expt i 0) 1.0d0))
84  t)
85
86(deftest expt.6
87  (loop for i = (random 1.0l10)
88        repeat 1000
89        always (eql (expt i 0) 1.0l0))
90  t)
91
92(deftest expt.7
93  (loop for i from -1000 to 1000
94        for c = (complex i i)
95        always (eql (expt c 0) 1))
96  t)
97
98(deftest expt.8
99  (loop for i = (random 1.0s3)
100        for c = (complex i i)
101        repeat 1000
102        always (eql (expt c 0) #c(1.0s0 0.0s0)))
103  t)
104
105(deftest expt.9
106  (loop for i = (random 1.0f6)
107        for c = (complex i i)
108        repeat 1000
109        always (eql (expt c 0) #c(1.0f0 0.0f0)))
110  t)
111
112(deftest expt.10
113  (loop for i = (random 1.0d10)
114        for c = (complex i i)
115        repeat 1000
116        always (eql (expt c 0) #c(1.0d0 0.0d0)))
117  t)
118
119(deftest expt.11
120  (loop for i = (random 1.0l10)
121        for c = (complex i i)
122        repeat 1000
123        always (eql (expt c 0) #c(1.0l0 0.0l0)))
124  t)
125
126(deftest expt.12
127  (loop for x in *numbers*
128        unless (or (floatp (realpart x))
129                   (eql (expt x 1) x))
130        collect x)
131  nil)
132
133(deftest expt.13
134  (loop for x in *rationals*
135        unless (and (eql (expt x 2) (* x x))
136                    (or (zerop x)
137                        (eql (expt x -1) (/ x))))
138        collect x)
139  nil)
140
141(deftest expt.14
142  (expt #c(0 2) 2)
143  -4)
144
145(deftest expt.15
146  (expt #c(1 1) 2)
147  #c(0 2))
148
149(deftest expt.16
150  (expt #c(1/2 1/3) 3)
151  #c(-1/24 23/108))
152
153(deftest expt.17
154  (expt #c(1 1) -2)
155  #c(0 -1/2))
156
157(deftest expt.18
158  (loop
159   for zero in '(0.0s0 0.0f0 0.0d0 0.0l0)
160   always
161   (loop for i from -1000 to 1000
162         always (or (zerop i)
163                    (eql (expt i zero) (float 1 zero)))))
164  t)
165
166(deftest expt.19
167  (loop
168   for zero in '(0.0s0 0.0f0 0.0d0 0.0l0)
169   always
170   (loop for i from -1000 to 1000
171         always (or (zerop i)
172                    (eql (expt (float i 0.0s0) zero) (float 1 zero)))))
173  t)
174
175(deftest expt.20
176  (loop
177   for zero in '(0.0f0 0.0d0 0.0l0)
178   always
179   (loop for i from -1000 to 1000
180         always (or (zerop i)
181                    (eql (expt (float i 0.0f0) zero) (float 1 zero)))))
182  t)
183
184(deftest expt.21
185  (loop
186   for zero in '(0.0d0 0.0l0)
187   always
188   (loop for i from -1000 to 1000
189         always (or (zerop i)
190                    (eql (expt (float i 0.0d0) zero) (float 1 zero)))))
191  t)
192
193(deftest expt.22
194  (expt 2.0f0 0.0s0)
195  1.0f0)
196
197(deftest expt.23
198  (expt 2.0d0 0.0s0)
199  1.0d0)
200
201(deftest expt.24
202  (expt 2.0l0 0.0s0)
203  1.0l0)
204
205(deftest expt.25
206  (expt 2.0d0 0.0f0)
207  1.0d0)
208
209(deftest expt.26
210  (expt 2.0l0 0.0f0)
211  1.0l0)
212
213(deftest expt.27
214  (expt 2.0l0 0.0d0)
215  1.0l0)
216
217(deftest expt.28
218  (<= (realpart (expt -8 1/3)) 0.0)
219  nil)
220
221#|
222;;; FIXME
223;;; I need to think more about how to do approximate float
224;;; equality in a principled way.
225
226(deftest expt.29
227  (loop for bound in '(1.0s4 1.0f6 1.0d8 1.0l8)
228        for ebound in (list short-float-epsilon single-float-epsilon
229                            double-float-epsilon long-float-epsilon)
230        for ebound2 = (max (* 2 ebound) (/ bound))
231        nconc
232        (loop for x = (1+ (random 1.0f6))
233              for s1 = (sqrt x)
234              for s2 = (expt x 1/2)
235              for error = (/ (abs (- s2 s2)) x)
236              repeat 1000
237              unless (< error ebound2)
238              collect (list x s1 s2)))
239  nil)
240
241(deftest expt.30
242  (loop for bound in '(1.0s4 1.0f6 1.0d8 1.0l8)
243        for ebound in (list short-float-epsilon single-float-epsilon
244                            double-float-epsilon long-float-epsilon)
245        for ebound2 = (max (* 2 ebound) (/ bound))
246        nconc
247        (loop for x = (- (1+ (random 1.0f6)))
248              for s1 = (sqrt x)
249              for s2 = (expt x 1/2)
250              for error = (/ (abs (- s2 s2)) x)
251              repeat 1000
252              unless (< error ebound2)
253              collect (list x s1 s2)))
254  nil)
255|#
Note: See TracBrowser for help on using the repository browser.