~ chicken-core (master) /tests/numbers-test.scm
Trap1;;;; numbers-test.scm
2
3(include "test.scm")
4
5(import (chicken bitwise)
6 (chicken fixnum)
7 (chicken flonum)
8 (chicken format)
9 (chicken platform)
10 (chicken time))
11
12(import (only (scheme base) exact-integer-sqrt))
13
14;; The default "comparator" doesn't know how to deal with extended number types
15(current-test-comparator
16 (lambda (exp act)
17 (or (equal? exp act)
18 (if (or (and (cplxnum? exp) (number? act))
19 (and (cplxnum? act) (number? exp)))
20 (and (< (abs (real-part (- exp act)))
21 (current-test-epsilon))
22 (< (abs (imag-part (- exp act)))
23 (current-test-epsilon)))
24 (and (number? exp)
25 (inexact? exp)
26 (< (abs (- 1 (abs (if (zero? act) (+ 1 exp) (/ exp act)))))
27 (current-test-epsilon)))))))
28
29(test-begin "numbers")
30
31(current-test-epsilon 0) ;; We want exact comparisons
32
33(define max-fix most-positive-fixnum)
34(define min-fix most-negative-fixnum)
35;; The minimal bignum in the sense that any smaller makes it a fixnum
36(define min-big (+ most-positive-fixnum 1))
37
38(define 64-bits? (feature? #:64bit))
39
40(define (show x)
41 (print (and x (number->string x)))
42 x)
43
44;(set-gc-report! #t)
45
46(define max2 (+ max-fix max-fix))
47
48(define b1 (+ 22 max2)) ; 2147483668 or 4611686018427387928
49
50(define c1 (make-rectangular 33 44))
51(define c2 (make-rectangular -1.2 44))
52
53(define b2 (- min-fix 22))
54(define r1 (/ 33 44))
55(define r2 (/ 1000 44))
56
57;; Found with the pi-ratios benchmark (find-pi 10 20 50)
58(define pi 3.14159265358979323881089001960817518141234854964894)
59(define ratpi 314159265358979323881089001960817518141234854964894/100000000000000000000000000000000000000000000000000)
60
61(test-group "basic constructors"
62 (test-assert "some bignum (twice maxint)" (show max2))
63 (test-assert "some other bignum (2147483668 or 9223372036854775828)" (show b1))
64 (test-assert "negative bignum" (show b2))
65 (test-assert "exact complex" (show c1))
66 (test-assert "inexact complex" (show c2))
67 (test-assert "rational" (show r1))
68)
69
70(test-group "addition"
71 (test-equal "+: no arguments" (+) 0)
72 (test-equal "+: single argument" (+ 33) 33)
73 (test-equal "+: adding fixnums" (+ 33 44) 77)
74 (test-equal "+: adding fixnums (2nd negative)" (+ 33 -44) -11)
75 (test-equal "+: adding fix/flo" (+ 33 44.5) 77.5)
76 (test-assert "+: adding fix/big" (show (+ 22 max2)))
77 (test-assert "+: adding fix/rat" (show (+ 22 r1)))
78 (test-equal "+: adding fix/complex" (+ 99 c1) (make-rectangular 132 44))
79 (test-equal "+: adding complex/fix (inexact)" (+ c2 99) (make-rectangular 97.8 44))
80 (test-equal "+: flo/flo" (+ 3.4 5.6) 9.0)
81 (test-equal "+: flo/big"
82 (+ 3.4 b1)
83 (if 64-bits? 9223372036854775809.4 2147483671.4))
84 (test-assert "+: flo/rat" (show (+ 33.4 r1)))
85 (test-equal "+: flo/comp" (+ 3.4 c1) (make-rectangular 36.4 44))
86 (test-assert "+: big/rat" (show (+ b1 r1)))
87 (test-equal "+: comp+comp" (+ c1 c1) (make-rectangular 66 88))
88 (test-equal "+: comp+comp (inexact)" (+ c1 c2) (make-rectangular 31.8 88))
89 (test-equal "+: multiarg" (+ 33 44 55) 132)
90)
91
92(test-group "subtraction"
93
94 (test-equal "-: negate fix" (- 33) -33)
95 (test-equal "-: negate most negative fix" (- min-fix) min-big)
96 (test-equal "abs: most negative fix" (abs most-negative-fixnum) min-big)
97 (test-equal "-: negate flo" (- 33.2) -33.2)
98 (test-assert "-: negate rat" (show (- r1)))
99 (test-equal "-: double-negate big" (- (- b1)) b1)
100 (test-equal "-: negate comp" (- c1) (make-rectangular -33 -44))
101 (test-equal "-: fixnums" (- 33 44) -11)
102 (test-equal "-: fixnums (2nd negative)" (- 33 -44) 77)
103 (test-assert "-: fixnums (overflow)" (show (- min-fix min-fix)))
104 (test-equal "-: fix/flo" (- 33 44.5) -11.5)
105 (test-equal "-: flo/fix" (- 44.5 33) 11.5)
106 (test-assert "-: fix/big" (show (- 22 b2)))
107 (test-assert "-: big/fix" (show (- b2 22)))
108 (test-equal "-: big/fix (normalizing to fix)" (- min-big 1) max-fix)
109 (test-assert "-: fix/rat" (show (- 22 r1)))
110 (test-assert "-: rat/fix" (show (- r1 22)))
111 (test-equal "-: fix/complex" (- 99 c1) (make-rectangular 66 -44))
112 (test-equal "-: complex/fix" (- c1 99) (make-rectangular -66 44))
113 (test-equal "-: complex/fix (inexact)" (- c2 99) (make-rectangular -100.2 44))
114 (test-equal "-: fix/complex (inexact)" (- 99 c2) (make-rectangular 100.2 -44))
115 (test-equal "-: fix/complex (negative im)" (- 99 1+2i) 98-2i)
116 (test-equal "-: fix/complex (negative im, inexact)" (- 99 1.0+2.0i) 98.0-2.0i)
117 (test-equal "-: fix/complex (negative real, inexact)" (- 99 -1.0+2.0i) 100.0-2.0i)
118 (test-equal "-: rat/complex (negative real)" (- 3/2 -1+2i) 5/2-2i)
119
120 (parameterize ((current-test-epsilon 1e-10))
121 (test-equal "-: flo/flo" (- 5.6 3.4) 2.2))
122
123 (test-assert "-: flo/big" (show (- 3.4 b1)))
124 (test-assert "-: big/flo" (show (- b1 3.4)))
125 (test-assert "-: flo/rat" (show (- 3.4 r1)))
126 (test-assert "-: rat/flo" (show (- r1 3.4)))
127 (test-assert "-: big/rat" (show (- b1 r1)))
128 (test-assert "-: rat/big" (show (- r1 b1)))
129 (test-equal "-: flo/comp" (- 3.4 c1) (make-rectangular -29.6 -44))
130 (test-equal "-: comp/flo" (- c1 3.4) (make-rectangular 29.6 44))
131 (test-equal "-: comp-comp" (- c1 c1) 0)
132 (test-equal "-: comp-comp (inexact)" (- c1 c2) 34.2)
133 (test-equal "-: multiarg" (- 33 44 55) -66)
134)
135
136
137(test-group "multiplication"
138
139 (test-equal "*: no arguments" (*) 1)
140 (test-equal "*: single argument" (* 33) 33)
141 (test-equal "*: multiplying fixnums" (* 33 44) 1452)
142 (test-equal "*: multiplying fixnums (2nd negative)" (* 33 -44) -1452)
143 (test-equal "*: multiplying fix/flo" (* 33 44.5) 1468.5)
144 (test-assert "*: multiplying fix/big (-> 47244640212)" (show (* 22 max2)))
145 (test-assert "*: multiplying fix/rat" (show (* 33 r1)))
146 (test-equal "*: multiplying fix/complex" (* 99 c1) (make-rectangular 3267 4356))
147 (test-equal "*: multiplying complex/fix (inexact)" (* c2 99) (make-rectangular -118.8 4356.0))
148 (test-equal "*: multiplying most negative fixnum by one (edge case)"
149 (list (* most-negative-fixnum 1) (fixnum? (* most-negative-fixnum 1)))
150 (list most-negative-fixnum #t))
151 (test-equal "*: flo/flo" (* 3.4 5.6) 19.04)
152 (test-equal "*: flo/big"
153 (* 0.001 b1)
154 (if 64-bits? 9223372036854775.806 2147483.668))
155 (test-assert "*: flo/rat" (show (* 3.4 r1)))
156 (test-assert "*: big/rat" (show (* b1 r1)))
157 (test-equal "*: flo/comp" (* 3.4 c1) (make-rectangular 112.2 149.6))
158 (test-equal "*: comp*comp" (* c1 c1) (make-rectangular -847 2904))
159 (test-equal "*: comp*comp (inexact)" (* c1 c2) (make-rectangular -1975.6 1399.2))
160 (test-equal "*: multiarg" (* 33 44 55) 79860)
161)
162
163(test-group "division"
164
165 (test-assert "/: rec. fix" (show (/ 33)))
166 (test-assert "/: rec. flo" (show (/ 33.2)))
167 (test-assert "/: rec. rat" (show (/ r1)))
168 (test-assert "/: rec. big" (show (/ b1)))
169 (test-assert "/: rec. comp" (/ c1))
170 (test-assert "/: fixnums" (show (/ 33 44)))
171 (test-equal "/: fixnums (both negative, fixnum result)" (show (/ -2 -2)) 1)
172 (test-assert "/: fixnums (2nd negative)" (show (/ 33 -44)))
173 (test-assert "/: fixnums" (show (/ min-fix min-fix)))
174 (test-equal "/: fix/flo" (/ 33 44.5) (fp/ 33.0 44.5))
175 (test-equal "/: flo/fix" (/ 44.5 33) (fp/ 44.5 33.0))
176 (test-assert "/: fix/big" (show (/ 22 b2)))
177 (test-assert "/: big/fix" (show (/ b2 22)))
178 (test-assert "/: fix/rat" (show (/ 22 r1)))
179 (test-assert "/: rat/fix" (show (/ r1 22)))
180 (test-assert "/: fix/complex" (show (/ 99 c1)))
181 (test-assert "/: complex/fix" (show (/ c1 99)))
182 (test-assert "/: complex/fix (inexact)" (show (- c2 99)))
183 (test-assert "/: fix/complex (inexact)" (show (- 99 c2)))
184 (test-equal "/: flo/flo" (/ 5.6 3.4) (fp/ 5.6 3.4))
185 (test-assert "/: flo/big" (show (/ 3.4 b1)))
186 (test-assert "/: big/flo" (show (/ b1 3.4)))
187 (test-assert "/: flo/rat" (show (/ 3.4 r1)))
188 (test-assert "/: rat/flo" (show (/ r1 3.4)))
189 (test-assert "/: big/rat" (show (/ b1 r1)))
190 (test-assert "/: rat/big" (show (/ r1 b1)))
191 (test-assert "/: rat/rat" (show (/ r1 r1)))
192 (test-assert "/: flo/comp" (show (/ 3.4 c1)))
193 (test-assert "/: comp/flo" (show (/ c1 3.4)))
194 (test-assert "/: comp/comp" (show (/ c1 c1)))
195 (test-assert "/: comp/comp (inexact)" (show (/ c1 c2)))
196 (test-equal "/: rat/complex" (/ 1/2 1+2i) 1/10-1/5i)
197 (test-equal "/: rat/complex (negative im)" (/ 1/2 1-2i) 1/10+1/5i)
198 (test-equal "/: rat/complex (negative real)" (/ 1/2 -1+2i) -1/10-1/5i)
199 (test-equal "/: rat/complex (negative real&im)" (/ 1/2 -1-2i) -1/10+1/5i)
200
201 (test-assert "/: multiarg" (show (/ 66 2 44)))
202 (test-error "/: div fixnum by 0" (/ 33 0))
203 ;; R7RS says it is an error if any but the first argument is an exact
204 ;; zero. R5RS doesn't say anything at all (??).
205 (test-error "/: div flonum by 0" (/ 33.0 0))
206 (test-equal "/: div fixnum by 0.0" (/ 33 0.0) +inf.0)
207 (test-equal "/: div flonum by 0.0" (/ 33.0 0.0) +inf.0)
208 (test-equal "/: div by 0 (inexact)" (/ 33 0.0) +inf.0)
209 (test-assert "/: big result" (show (/ b1 2)))
210)
211
212(test-group "quotient"
213 (test-equal "quotient: fix/fix" (quotient 22 11) 2)
214 (test-equal "quotient: fix/big" (quotient 22 b1) 0)
215 (test-equal "quotient: fix/big (most negative)" (quotient min-fix (- min-fix)) -1)
216 (test-equal "quotient: big/fix (most negative)" (quotient (- min-fix) min-fix) -1)
217 (test-equal "quotient: fix/fix (most negative)" (quotient min-fix -1) (* min-fix -1))
218 (test-equal "quotient: flo/flo" (quotient 22.0 11.0) 2.0)
219 (test-equal "quotient: fix/flo" (quotient 22 11.0) 2.0)
220 (test-equal "quotient: flo/fix" (quotient 22.0 11) 2.0)
221 (test-equal "quotient: flo/big" (quotient 22.0 b1) 0.0)
222 (test-equal "quotient: big/flo" (quotient b1 (/ b1 2.0)) 2.0)
223 (test-equal "quotient: big/big" (quotient (- min-fix) (- min-fix)) 1)
224 (test-equal "quotient: big/big" (quotient (+ (- min-fix) 5) (- min-fix)) 1)
225
226 (test-error "quotient: flo/flo (fractional)" (quotient 23.0 11.5))
227 (test-error "quotient: fix/flo (fractional)" (quotient 23 11.5))
228 (test-error "quotient: flo/fix (fractional)" (quotient 13.5 6))
229)
230
231(test-group "remainder"
232 (test-equal "remainder: fix/fix" (remainder 22 11) 0)
233 (test-equal "remainder: fix/big" (remainder 22 b1) 22)
234 (test-equal "remainder: fix/big (most negative)" (remainder min-fix (- min-fix)) 0)
235 (test-equal "remainder: big/fix (most negative)" (remainder (- min-fix) min-fix) 0)
236 (test-equal "remainder: big/big" (remainder (- min-fix) (- min-fix)) 0)
237 (test-equal "remainder: big/big" (remainder (+ (- min-fix) 5) (- min-fix)) 5)
238
239 (test-equal "remainder: flo/flo" (remainder 22.0 11.0) 0.0)
240 (test-equal "remainder: fix/flo" (remainder 22 11.0) 0.0)
241 (test-equal "remainder: flo/fix" (remainder 22.0 11) 0.0)
242 (unless 64-bits? ;; We lose so much precision when converting to double this makes no sense
243 (test-equal "remainder: flo/big" (remainder 22.0 b1) 22.0))
244
245 (test-error "remainder: flo/flo (fractional)" (remainder 22.5 2.25))
246 (test-error "remainder: fix/flo (fractional)" (remainder 6 12.5))
247 (test-error "remainder: flo/fix (fractional)" (remainder 13.5 6))
248 (unless 64-bits?
249 (test-error "remainder: flo/big (fractional)" (remainder (+ b1 0.5) b1)))
250)
251
252(test-group "quotient&remainder"
253 (test-equal "quotient&remainder: fix/fix"
254 (receive (quotient&remainder 22 11)) '(2 0))
255 (test-equal "quotient&remainder: fix/big"
256 (receive (quotient&remainder 22 b1)) '(0 22))
257 (test-equal "quotient&remainder: fix/big (most negative)"
258 (receive (quotient&remainder min-fix (- min-fix))) '(-1 0))
259 (test-equal "quotient&remainder: big/fix (most negative)"
260 (receive (quotient&remainder (- min-fix) min-fix)) '(-1 0))
261 (test-equal "quotient&remainder: fix/fix (most negative)"
262 (receive (quotient&remainder min-fix -1)) `(,(* min-fix -1) 0))
263 (test-equal "quotient&remainder: big/big" (receive (quotient&remainder (- min-fix) (- min-fix)))
264 '(1 0))
265 (test-equal "quotient&remainder: big/big" (receive (quotient&remainder (+ (- min-fix) 5) (- min-fix)))
266 '(1 5))
267
268 (test-equal "quotient&remainder: flo/flo"
269 (receive (quotient&remainder 22.0 4.0)) '(5.0 2.0))
270 (test-equal "quotient&remainder: flo/fix"
271 (receive (quotient&remainder 22.0 4)) '(5.0 2.0))
272 (test-equal "quotient&remainder: fix/flo"
273 (receive (quotient&remainder 22 4.0)) '(5.0 2.0))
274 (test-error "quotient&remainder: flo/fix (fractional)"
275 (receive (quotient&remainder 0.1 2)))
276 (test-error "quotient&remainder: flo/big (fractional)"
277 (receive (quotient&remainder 0.5 b1)))
278 (test-error "quotient&remainder: big/flo (fractional)"
279 (receive (quotient&remainder b1 0.5)))
280)
281
282(test-group "gcd"
283 (test-equal "gcd: fix (64-bit)/big" (gcd 907947775416515 11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111) 1)
284 (test-equal "gcd: big/big" (gcd 234897235923342343242 234790237101762305340234) 6)
285 (test-equal (gcd) 0)
286 (test-equal (gcd 6) 6)
287 (test-equal (gcd -2) 2)
288 (test-equal (gcd 6 8) 2)
289 (test-equal (gcd 6 8 5) 1)
290 (test-equal (gcd 6 -8 5) 1)
291 (test-equal (gcd 6.0) 6.0)
292 (test-equal (gcd 6.0 8.0) 2.0)
293 (test-error (gcd 6.1))
294 (test-error (gcd 6.1 8.0))
295 (test-error (gcd 6.0 8.1))
296 (test-error (gcd +inf.0))
297 (test-error (gcd +nan.0))
298 (test-error (gcd 6.0 +inf.0))
299 (test-error (gcd +inf.0 6.0))
300 (test-error (gcd +nan.0 6.0))
301 (test-error (gcd 6.0 +nan.0))
302 (test-error (gcd 1+2i 3+4i))
303 (test-error (gcd 1/2 3/4)))
304
305(test-group "lcm"
306 (test-equal (lcm) 1)
307 (test-equal (lcm 5) 5)
308 (test-equal (lcm -8) 8)
309 (test-equal (lcm 6 8) 24)
310 (test-equal (lcm 6 8 5) 120)
311 (test-equal (lcm 6.0 8.0) 24.0)
312 (test-error (lcm 6.1 8.0))
313 (test-error (lcm 6.0 8.1))
314 (test-error (lcm +inf.0))
315 (test-error (lcm +nan.0))
316 (test-error (lcm 6.0 +inf.0))
317 (test-error (lcm +inf.0 6.0))
318 (test-error (lcm +nan.0 6.0))
319 (test-error (lcm 6.0 +nan.0))
320 (test-error (lcm 1+2i 3+4i))
321 (test-error (lcm 1/2 3/4)))
322
323
324(test-group "equality"
325
326 (test-equal "=: fix/fix" (= 33 33) #t)
327 (test-equal "=: fix/flo" (= 33 33.0) #t)
328 (test-equal "=: !fix/fix" (= 33 34) #f)
329 (test-equal "=: !fix/flo" (= 33 33.1) #f)
330 (test-equal "=: !fix/flo (overflow)" (= 9007199254740993 9007199254740992.0) #f)
331 (test-equal "=: !fix/flo (inf)" (= 0 +inf.0) #f)
332 (test-equal "=: !fix/flo (-inf)" (= 0 -inf.0) #f)
333 (test-equal "=: !fix/flo (+nan)" (= 0 -nan.0) #f)
334 (test-equal "=: flo/fix" (= 33.0 33) #t)
335 (test-equal "=: !flo/fix (overflow)" (= 9007199254740992.0 9007199254740993) #f)
336 (test-equal "=: !flo/fix (inf)" (= +inf.0 0) #f)
337 (test-equal "=: !flo/fix (-inf)" (= -inf.0 0) #f)
338 (test-equal "=: !flo/fix (+nan)" (= -nan.0 0) #f)
339 (test-equal "=: flo/flo" (= 33.1 33.1) #t)
340 (test-equal "=: !flo/flo" (= 33.1 -33.1) #f)
341 ;; Flonums are only 53 bits of precision, so it will drop data.
342 ;; Comparison is exact
343 (unless 64-bits?
344 (test-equal "=: big/flo" (= b1 (+ 0.0 b1)) #t))
345 (test-equal "=: big/big" (= b1 b1) #t)
346 (test-equal "=: !big/big" (= b2 b1) #f)
347 (test-equal "=: rat/flo" (= r1 (+ r1 0.0)) #t)
348 (test-equal "=: rat/rat" (= r1 r1) #t)
349 (test-equal "=: !rat/rat" (= r1 r2) #f)
350 (test-equal "=: comp/comp" (= c1 c1) #t)
351 (test-equal "=: !comp/comp" (= c1 c2) #f)
352)
353
354(test-group "generic equality"
355 (test-equal "equal?: fix/fix" (equal? 33 33) #t)
356 (test-equal "equal?: fix/flo" (equal? 33 33.0) #f)
357 (test-equal "equal?: !fix/fix" (equal? 33 34) #f)
358 (test-equal "equal?: !fix/flo" (equal? 33 33.1) #f)
359 (test-equal "equal?: flo/fix" (equal? 33.0 33) #f)
360 (test-equal "equal?: flo/flo" (equal? 33.1 33.1) #t)
361 (test-equal "equal?: !flo/flo" (equal? 33.1 -33.1) #f)
362 (test-equal "equal?: big/flo" (equal? b1 (+ 0.0 b1)) #f)
363 (test-equal "equal?: big/big" (equal? b1 b1) #t)
364 (test-equal "equal?: big/big2" (equal? b1 (+ 1 b1 -1)) #t)
365 (test-equal "equal?: !big/big" (equal? b2 b1) #f)
366 (test-equal "equal?: rat/flo" (equal? r1 (+ r1 0.0)) #f)
367 (test-equal "equal?: rat/rat" (equal? r1 r1) #t)
368 (test-equal "equal?: !rat/rat" (equal? r1 r2) #f)
369 (test-equal "equal?: comp/comp" (equal? c1 c1) #t)
370 (test-equal "equal?: !comp/comp" (equal? c1 c2) #f)
371 (test-equal "equal?: nan/nan" (equal? (/ 0.0 0.0) (/ 0.0 0.0)) #f)
372 (test-equal "equal?: nan+nan/nan+nan" (equal? (make-rectangular (/ 0.0 0.0)
373 (/ 0.0 0.0))
374 (make-rectangular (/ 0.0 0.0)
375 (/ 0.0 0.0))) #f)
376)
377
378
379(test-group "greater & greater/equal"
380
381 (test-equal ">: fix/fix" (> 44 33) #t)
382 (test-equal ">=: fix/fix" (>= 44 33) #t)
383 (test-equal ">: fix/fix/fix" (> 44 33 22) #t)
384 (test-equal ">=: fix/fix/fix" (>= 44 33 22) #t)
385 (test-equal ">: !fix/fix" (> 33 44) #f)
386 (test-equal ">=: !fix/fix" (>= 33 44) #f)
387 (test-equal ">: !fix/fix/fix" (> 22 33 44) #f)
388 (test-equal ">=: !fix/fix/fix" (>= 22 33 44) #f)
389 (test-equal ">: fix/fix" (> 33 33) #f)
390 (test-equal ">=: !fix/fix" (>= 33 33) #t)
391 (test-equal ">: fix/flo" (> 44 33.0) #t)
392 (test-equal ">=: fix/flo" (>= 44 33.0) #t)
393 (test-equal ">: !fix/flo" (> 33 44.0) #f)
394 (test-equal ">=: !fix/flo" (>= 33 44.0) #f)
395 (test-equal ">: !fix/flo" (> 33 33.0) #f)
396 (test-equal ">=: !fix/flo" (>= 33 33.0) #t)
397 (test-equal ">: fix/flo (flo overflow), on 64 bits"
398 (> 9007199254740993 9007199254740992.0) #t) ; 2^53
399 (test-equal ">=: fix/flo (flo overflow), on 64 bits"
400 (>= 9007199254740993 9007199254740992.0) #t)
401 (test-equal ">: fix/flo (flo underflow), on 64 bits"
402 (> -9007199254740992 -9007199254740991.0) #f)
403 (test-equal ">=: fix/flo (flo underflow), on 64 bits"
404 (>= -9007199254740992 -9007199254740991.0) #f)
405 (test-equal ">: fix/big" (> 44 b2) #t)
406 (test-equal ">=: fix/big" (>= 44 b2) #t)
407 (test-equal ">: !fix/big" (> 33 b1) #f)
408 (test-equal ">=: !fix/big" (>= 33 b1) #f)
409 (test-equal ">: fix/rat" (> 44 r1) #t)
410 (test-equal ">=: fix/rat" (>= 44 r1) #t)
411 (test-equal ">: !fix/rat" (> 0 r1) #f)
412 (test-equal ">=: !fix/rat" (>= 0 r1) #f)
413
414 (test-equal ">: flo/fix" (> 44.0 33) #t)
415 (test-equal ">=: flo/fix" (>= 44.0 33) #t)
416 (test-equal ">: !flo/fix" (> 33.0 44) #f)
417 (test-equal ">=: !flo/fix" (>= 33.0 44) #f)
418 (test-equal ">: !flo/fix" (> 33.0 33) #f)
419 (test-equal ">=: flo/fix" (>= 33.0 33) #t)
420 (test-equal ">: flo/flo" (> 44.0 33.0) #t)
421 (test-equal ">=: flo/flo" (>= 44.0 33.0) #t)
422 (test-equal ">: !flo/flo" (> 33.0 44.0) #f)
423 (test-equal ">=: !flo/flo" (>= 33.0 44.0) #f)
424 (test-equal ">: flo/big" (> 44.0 b2) #t)
425 (test-equal ">=: flo/big" (>= 44.0 b2) #t)
426 (test-equal ">: flo/fix (flo overflow), on 64 bits"
427 (> 9007199254740992.0 9007199254740993) #f) ; 2^53
428 (test-equal ">=: flo/fix (flo overflow), on 64 bits"
429 (>= 9007199254740992.0 9007199254740993) #f)
430 (test-equal ">: fix/flo (flo underflow), on 64 bits"
431 (> -9007199254740991.0 -9007199254740992) #t)
432 (test-equal ">=: fix/flo (flo underflow), on 64 bits"
433 (>= -9007199254740991.0 -9007199254740992) #t)
434 (test-equal ">: flo/big (flo overflow)"
435 (> 1237940039285380274899124224.0 1237940039285380274899124225) #f)
436 (test-equal ">=: flo/big (flo overflow)"
437 (>= 1237940039285380274899124224.0 1237940039285380274899124225) #f)
438 (test-equal ">: !flo/big" (> 33.0 b1) #f)
439 (test-equal ">=: !flo/big" (>= 33.0 b1) #f)
440 (test-equal ">: flo/rat" (> 44.0 r1) #t)
441 (test-equal ">=: flo/rat" (>= 44.0 r1) #t)
442 (test-equal ">: !flo/rat" (> 0.0 r1) #f)
443 (test-equal ">=: !flo/rat" (>= 0.0 r1) #f)
444 (test-equal ">: !rat/rat" (> r1 r1) #f)
445 (test-equal ">=: rat/rat" (>= r1 r1) #t)
446 (test-equal ">: flo/nan" (> 0.0 +nan.0) #f)
447 (test-equal ">=: flo/nan" (>= 0.0 +nan.0) #f)
448 (test-equal ">: nan/flo" (> +nan.0 0.0) #f)
449 (test-equal ">=: nan/flo" (>= +nan.0 0.0) #f)
450 (test-equal ">: flo/flo/nan" (> 1.0 0.0 +nan.0) #f)
451 (test-equal ">=: flo/flo/nan" (>= 1.0 0.0 +nan.0) #f)
452
453 (test-equal ">: big/fix" (> b1 33) #t)
454 (test-equal ">=: big/fix" (>= b1 33) #t)
455 (test-equal ">: !big/fix" (> b2 44) #f)
456 (test-equal ">=: !big/fix" (>= b2 44) #f)
457 (test-equal ">: big/flo" (> b1 33.0) #t)
458 (test-equal ">=: big/flo" (>= b1 33.0) #t)
459 (test-equal ">: big/flo (flo overflow)"
460 (> 1237940039285380274899124225 1237940039285380274899124224.0) #t)
461 (test-equal ">=: big/flo (flo overflow)"
462 (>= 1237940039285380274899124225 1237940039285380274899124224.0) #t)
463 (test-equal ">: !big/flo" (> b2 44.0) #f)
464 (test-equal ">=: !big/flo" (>= b2 44.0) #f)
465 (test-equal ">: big/big" (> b1 b2) #t)
466 (test-equal ">=: big/big" (>= b1 b2) #t)
467 (test-equal ">: !big/big" (> b2 b1) #f)
468 (test-equal ">=: !big/big" (>= b2 b1) #f)
469 (test-equal ">: big/rat" (> b1 r1) #t)
470 (test-equal ">=: big/rat" (>= b1 r1) #t)
471 (test-equal ">: !big/rat" (> b2 r1) #f)
472 (test-equal ">=: !big/rat" (>= b2 r1) #f)
473
474 (test-equal ">: rat/fix" (> r1 2) #f)
475 (test-equal ">=: rat/fix" (>= r1 2) #f)
476 (test-equal ">: !rat/fix" (> r1 44) #f)
477 (test-equal ">=: !rat/fix" (>= r1 44) #f)
478 (test-equal ">: rat/flo" (> r2 2.0) #t)
479 (test-equal ">=: rat/flo" (>= r2 2.0) #t)
480 (test-equal ">: !rat/flo" (> b2 44.0) #f)
481 (test-equal ">=: !rat/flo" (>= b2 44.0) #f)
482 (test-equal ">: !rat/big" (> r1 b1) #f)
483 (test-equal ">=: !rat/big" (>= r1 b1) #f)
484 (test-equal ">: rat/rat" (> r2 r1) #t)
485 (test-equal ">=: rat/rat" (>= r2 r1) #t)
486 (test-equal ">: !rat/rat" (> r1 r2) #f)
487 (test-equal ">=: !rat/rat" (>= r1 r2) #f)
488 (test-equal ">: rat/flo (flo overflow)"
489 (> 1237940039285380274899124224/1237940039285380274899124223 1.0) #t)
490 (test-equal ">: rat/flo (flo overflow)"
491 (> 1237940039285380274899124224/1237940039285380274899124223 1.5) #f)
492 (test-equal ">=: rat/flo (flo overflow)"
493 (>= 1237940039285380274899124224/1237940039285380274899124223 1.0) #t)
494 (test-equal ">=: rat/flo (flo overflow)"
495 (>= 1237940039285380274899124224/1237940039285380274899124223 1.5) #f)
496 (test-equal ">: rat/flo (flo underflow)"
497 (> -1237940039285380274899124224/1237940039285380274899124223 -1.0) #f)
498 (test-equal ">: rat/flo (flo underflow)"
499 (> -1237940039285380274899124224/1237940039285380274899124223 -1.5) #t)
500 (test-equal ">=: rat/flo (flo underflow)"
501 (>= -1237940039285380274899124224/1237940039285380274899124223 -1.0) #f)
502 (test-equal ">=: rat/flo (flo underflow)"
503 (>= -1237940039285380274899124224/1237940039285380274899124223 -1.5) #t)
504)
505
506
507(test-group "less & less/equal"
508
509 (test-equal "<: !fix/fix" (< 44 33) #f)
510 (test-equal "<=: !fix/fix" (<= 44 33) #f)
511 (test-equal "<: fix/fix/fix" (< 33 44 55) #t)
512 (test-equal "<=: fix/fix/fix" (<= 33 44 55) #t)
513 (test-equal "<: !fix/fix/fix" (< 33 55 44) #f)
514 (test-equal "<=: !fix/fix/fix" (<= 33 55 44) #f)
515 (test-equal "<: !fix/fix/fix" (< 44 33 55) #f)
516 (test-equal "<=: !fix/fix/fix" (<= 44 33 55) #f)
517 (test-equal "<: !fix/fix/fix" (< 44 44 44) #f)
518 (test-equal "<=: fix/fix/fix" (<= 44 44 44) #t)
519 (test-equal "<: fix/fix" (< 33 44) #t)
520 (test-equal "<=: fix/fix" (<= 33 44) #t)
521 (test-equal "<: !fix/fix" (< 33 33) #f)
522 (test-equal "<=: fix/fix" (<= 33 33) #t)
523 (test-equal "<: !fix/flo" (< 44 33.0) #f)
524 (test-equal "<=: !fix/flo" (<= 44 33.0) #f)
525 (test-equal "<: fix/flo" (< 33 44.0) #t)
526 (test-equal "<=: fix/flo" (<= 33 44.0) #t)
527 (test-equal "<: fix/flo (flo overflow), on 64 bits"
528 (< 9007199254740993 9007199254740992.0) #f) ; 2^53
529 (test-equal "<=: fix/flo (flo overflow), on 64 bits"
530 (< 9007199254740993 9007199254740992.0) #f)
531 (test-equal "<: fix/flo (flo underflow), on 64 bits"
532 (< -9007199254740993 -9007199254740992.0) #t)
533 (test-equal "<=: fix/flo (flo underflow), on 64 bits"
534 (<= -9007199254740993 -9007199254740992.0) #t)
535 (test-equal "<: !fix/flo" (< 33.0 33.0) #f)
536 (test-equal "<=: fix/flo" (<= 33.0 33.0) #t)
537 (test-equal "<: !fix/big" (< 44 b2) #f)
538 (test-equal "<=: !fix/big" (<= 44 b2) #f)
539 (test-equal "<: fix/big" (< 33 b1) #t)
540 (test-equal "<=: fix/big" (<= 33 b1) #t)
541 (test-equal "<: !big/big" (< b1 b1) #f)
542 (test-equal "<=: big/big" (<= b1 b1) #t)
543 (test-equal "<: !fix/rat" (< 44 r1) #f)
544 (test-equal "<=: !fix/rat" (<= 44 r1) #f)
545 (test-equal "<: fix/rat" (< 0 r1) #t)
546 (test-equal "<=: fix/rat" (<= 0 r1) #t)
547
548 (test-equal "<: !flo/fix" (< 44.0 33) #f)
549 (test-equal "<=: !flo/fix" (<= 44.0 33) #f)
550 (test-equal "<: flo/fix" (< 33.0 44) #t)
551 (test-equal "<=: flo/fix" (<= 33.0 44) #t)
552 (test-equal "<: !flo/flo" (< 44.0 33.0) #f)
553 (test-equal "<=: !flo/flo" (<= 44.0 33.0) #f)
554 (test-equal "<: flo/flo" (< 33.0 44.0) #t)
555 (test-equal "<=: flo/flo" (<= 33.0 44.0) #t)
556 (test-equal "<: !flo/big" (< 44.0 b2) #f)
557 (test-equal "<=: !flo/big" (<= 44.0 b2) #f)
558 (test-equal "<: flo/big" (< 33.0 b1) #t)
559 (test-equal "<=: flo/big" (<= 33.0 b1) #t)
560 (test-equal "<: flo/fix (flo overflow), on 64 bits"
561 (< 9007199254740992.0 9007199254740993) #t) ; 2^53
562 (test-equal "<=: flo/fix (flo overflow), on 64 bits"
563 (< 9007199254740992.0 9007199254740993) #t)
564 (test-equal "<: flo/fix (flo underflow), on 64 bits"
565 (< -9007199254740992.0 -9007199254740993) #f)
566 (test-equal "<=: flo/fix (flo underflow), on 64 bits"
567 (<= -9007199254740992.0 -9007199254740993) #f)
568 (test-equal "<: flo/big (flo overflow)"
569 (< 1237940039285380274899124224.0 1237940039285380274899124225) #t)
570 (test-equal "<=: flo/big (flo overflow)"
571 (<= 1237940039285380274899124224.0 1237940039285380274899124225) #t)
572 (test-equal "<: !flo/rat" (< 44.0 r1) #f)
573 (test-equal "<=: !flo/rat" (<= 44.0 r1) #f)
574 (test-equal "<: flo/rat" (< 0.0 r1) #t)
575 (test-equal "<=: flo/rat" (<= 0.0 r1) #t)
576 (test-equal "<: flo/nan" (< 0.0 +nan.0) #f)
577 (test-equal "<=: flo/nan" (<= 0.0 +nan.0) #f)
578 (test-equal "<: nan/flo" (< +nan.0 0.0) #f)
579 (test-equal "<=: nan/flo" (<= +nan.0 0.0) #f)
580 (test-equal "<: flo/flo/nan" (< 0.0 1.0 +nan.0) #f)
581 (test-equal "<=: flo/flo/nan" (<= 0.0 1.0 +nan.0) #f)
582
583 (test-equal "<: !big/fix" (< b1 33) #f)
584 (test-equal "<=: !big/fix" (<= b1 33) #f)
585 (test-equal "<: big/fix" (< b2 44) #t)
586 (test-equal "<=: big/fix" (<= b2 44) #t)
587 (test-equal "<: !big/flo" (< b1 33.0) #f)
588 (test-equal "<=: !big/flo" (<= b1 33.0) #f)
589 (test-equal "<: big/flo" (< b2 44.0) #t)
590 (test-equal "<=: big/flo" (<= b2 44.0) #t)
591 (test-equal "<: big/flo (max flo)"
592 (< 1237940039285380274899124224 1237940039285380274899124224.0) #f)
593 (test-equal "<=: big/flo (max flo)"
594 (<= 1237940039285380274899124224 1237940039285380274899124224.0) #t)
595 (test-equal "<: big/flo (max flo, smaller bignum)"
596 (< 1237940039285380274899124223 1237940039285380274899124224.0) #t)
597 (test-equal "<: big/flo (max flo, smaller bignum)"
598 (<= 1237940039285380274899124223 1237940039285380274899124224.0) #t)
599 (test-equal "<: !big/big" (< b1 b2) #f)
600 (test-equal "<=: !big/big" (<= b1 b2) #f)
601 (test-equal "<: big/big" (< b2 b1) #t)
602 (test-equal "<=: big/big" (<= b2 b1) #t)
603 (test-equal "<: !big/rat" (< b1 r1) #f)
604 (test-equal "<=: !big/rat" (<= b1 r1) #f)
605 (test-equal "<: big/rat" (< b2 r1) #t)
606 (test-equal "<=: big/rat" (<= b2 r1) #t)
607
608 (test-equal "<: !rat/fix" (< r2 2) #f)
609 (test-equal "<=: !rat/fix" (<= r2 2) #f)
610 (test-equal "<: rat/fix" (< r1 44) #t)
611 (test-equal "<=: rat/fix" (<= r1 44) #t)
612 (test-equal "<: !rat/flo" (< r2 2.0) #f)
613 (test-equal "<=: !rat/flo" (<= r2 2.0) #f)
614 (test-equal "<: rat/flo" (< b2 44.0) #t)
615 (test-equal "<=: rat/flo" (<= b2 44.0) #t)
616 (test-equal "<: rat/big" (< r1 b1) #t)
617 (test-equal "<=: rat/big" (<= r1 b1) #t)
618 (test-equal "<: !rat/rat" (< r2 r1) #f)
619 (test-equal "<=: !rat/rat" (<= r2 r1) #f)
620 (test-equal "<: rat/rat" (< r1 r2) #t)
621 (test-equal "<=: rat/rat" (<= r1 r2) #t)
622 (test-equal "<: rat/flo (flo overflow)"
623 (< 1237940039285380274899124224/1237940039285380274899124223 1.0) #f)
624 (test-equal "<: rat/flo (flo overflow)"
625 (< 1237940039285380274899124224/1237940039285380274899124223 1.5) #t)
626 (test-equal "<=: rat/flo (flo overflow)"
627 (<= 1237940039285380274899124224/1237940039285380274899124223 1.0) #f)
628 (test-equal "<=: rat/flo (flo overflow)"
629 (<= 1237940039285380274899124224/1237940039285380274899124223 1.5) #t)
630 (test-equal "<: rat/flo (flo underflow)"
631 (< -1237940039285380274899124224/1237940039285380274899124223 -1.0) #t)
632 (test-equal "<: rat/flo (flo underflow)"
633 (< -1237940039285380274899124224/1237940039285380274899124223 -1.5) #f)
634 (test-equal "<=: rat/flo (flo underflow)"
635 (<= -1237940039285380274899124224/1237940039285380274899124223 -1.0) #t)
636 (test-equal "<=: rat/flo (flo underflow)"
637 (<= -1237940039285380274899124224/1237940039285380274899124223 -1.5) #f)
638)
639
640(test-group "complex"
641
642 (test-equal "real-part" (real-part c1) 33)
643 (test-equal "real-part of flonum" (real-part 1.23) 1.23)
644 (test-equal "real-part of fixnum" (real-part 123) 123)
645 (test-equal "real-part of ratnum" (real-part 1/2) 1/2)
646 (test-equal "real-part of bignum" (real-part b1) b1)
647 (test-equal "real-part of negative flonum" (real-part -1.23) -1.23)
648 (test-equal "real-part of negative fixnum" (real-part -123) -123)
649 (test-equal "real-part of negative ratnum" (real-part -1/2) -1/2)
650 (test-equal "real-part of negative bignum" (real-part (- b1)) (- b1))
651 (test-equal "imag-part" (imag-part c1) 44)
652 (test-equal "imag-part of flonum" (imag-part 1.23) 0.0)
653 (test-equal "imag-part of fixnum" (imag-part 123) 0)
654 (test-equal "imag-part of ratnum" (imag-part 1/2) 0)
655 (test-equal "imag-part of bignum" (imag-part b1) 0)
656 (test-assert "make-polar" (show (make-polar 33 44)))
657 (test-equal "magnitude" (magnitude 0+8i) 8)
658 (test-equal "magnitude" (magnitude 0+1/2i) 1/2)
659 (test-equal "magnitude of flonum" (magnitude 1.23) 1.23)
660 (test-equal "magnitude of fixnum" (magnitude 123) 123)
661 (test-equal "magnitude of ratnum" (magnitude 1/2) 1/2)
662 (test-equal "magnitude of bignum" (magnitude b1) b1)
663 (test-equal "magnitude of negative flonum" (magnitude -1.23) 1.23)
664 (test-equal "magnitude of negative fixnum" (magnitude -123) 123)
665 (test-equal "magnitude of negative ratnum" (magnitude -1/2) 1/2)
666 (test-equal "magnitude of negative bignum" (magnitude (- b1)) b1)
667 (test-assert "angle" (show (angle c1)))
668 (test-equal "angle of flonum" (angle 1.23) 0.0)
669 (test-equal "angle of fixnum" (angle 123) 0.0)
670 (test-equal "angle of ratnum" (angle 1/2) 0.0)
671 (test-equal "angle of bignum" (angle b1) 0.0)
672 (test-equal "angle of negative flonum" (angle -1.23) pi)
673 (test-equal "angle of negative fixnum" (angle -123) pi)
674 (test-equal "angle of negative ratnum" (angle -1/2) pi)
675 (test-equal "angle of negative bignum" (angle (- b1)) pi)
676)
677
678(test-group "rational"
679
680 ;; Use equal? instead of = to check equality and exactness in one go
681 (parameterize ((current-test-comparator equal?))
682 (test-assert (show (numerator b1)))
683 (test-equal (numerator r1) 3)
684 (test-equal (numerator 33) 33)
685 (test-equal (denominator r1) 4)
686 (test-equal (denominator b1) 1)
687 (test-equal (denominator 33) 1)
688 (test-equal (numerator 0) 0)
689 (test-equal (denominator 0) 1)
690 (test-equal (numerator 3) 3)
691 (test-equal (denominator 3) 1)
692 (test-equal (numerator -3) -3)
693 (test-equal (denominator -3) 1)
694 (test-equal (numerator 0.5) 1.0)
695 (test-equal (denominator 0.5) 2.0)
696 (test-equal (numerator 1.25) 5.0)
697 (test-equal (denominator 1.25) 4.0)
698 (test-equal (numerator -1.25) -5.0)
699 (test-equal (denominator -1.25) 4.0)
700 (test-equal (numerator 1e10) 1e10)
701 (test-equal (denominator 1e10) 1.0))
702 (test-error (numerator +inf.0))
703 (test-error (numerator +nan.0))
704 (test-error (denominator +inf.0))
705 (test-error (denominator +nan.0))
706
707)
708
709(test-group "misc"
710
711 (test-equal "inexact->exact" (inexact->exact 2.3) 2589569785738035/1125899906842624)
712 (test-error "inexact->exact +inf" (inexact->exact +inf.0))
713 (test-error "inexact->exact -inf" (inexact->exact -inf.0))
714 (test-error "inexact->exact -NaN" (inexact->exact +nan.0))
715 (test-equal "sqrt (integer result)" (sqrt 16) 4)
716 (test-equal "sqrt (exact result)" (sqrt 1/4) 1/2)
717 (parameterize ((current-test-epsilon 1e-10))
718 (test-equal "sqrt (inexact result)" (sqrt 2) 1.4142135623730951))
719 (test-equal "sqrt (inexact input)" (sqrt 4.0) 2.0)
720 (test-equal "sqrt (exact large number)" (sqrt (* max-fix max-fix)) max-fix)
721 (test-error "exact-integer-sqrt (nonint flonum)" (exact-integer-sqrt 1.5))
722 (test-error "exact-integer-sqrt (ratnum)" (exact-integer-sqrt 1/2))
723 (test-error "exact-integer-sqrt (int flonum)" (exact-integer-sqrt 4.0))
724 (test-equal "exact-integer-sqrt (w/o rest)"
725 (receive x (exact-integer-sqrt (* max-fix max-fix)) x)
726 (list max-fix 0))
727 (test-equal "exact-integer-sqrt (with rest)"
728 (receive x (exact-integer-sqrt (+ (* max-fix max-fix) 5)) x)
729 (list max-fix 5))
730 (test-equal "exact-integer-nth-root without rest"
731 (receive x (exact-integer-nth-root 243 5) x)
732 (list 3 0))
733 (test-equal "exact-integer-nth-root with rest"
734 (receive x (exact-integer-nth-root 128 4) x)
735 (list 3 47))
736 (test-equal "exact-integer-nth-root with insanely large base"
737 (receive x (exact-integer-nth-root 5 (if 64-bits? 10000000000 100000000)) x)
738 (list 1 4))
739 (test-equal "expt" (expt 2 4) 16)
740 (test-assert "expt" (show (expt 2 100)))
741 ;; The next three according to R7RS
742 (test-equal "expt 0.0^0.0)" (expt 0.0 0.0) 1.0)
743 (test-equal "expt 0.0^{pos}" (expt 0.0 1.0) 0.0)
744 ;; An error is not mandatory:
745 ;; "[...] either an error is signalled or an unspecified number is returned."
746 ;(test-error "expt 0.0^{neg}" (expt 0.0 -1.0))
747 ;; R7 doesn't say anything specific about fixnums, so I guess this should behave the same
748 (test-equal "expt 0^0" (expt 0 0) 1)
749 (test-equal "expt 0^{pos}" (expt 0 1) 0)
750 (test-error "expt 0^{neg}" (expt 0 -1))
751 (test-equal "expt (rat base)" (expt 1/2 2) 1/4)
752 (test-equal "expt (rat exponent)" (expt 16 1/4) 2)
753 (test-equal "expt (negative rat exponent)" (expt 16 -1/4) 1/2)
754 (test-equal "expt (inexact from rat exponent)" (expt 2 1/7) 1.1040895136738123)
755 (test-equal "expt (> 1 rat exponent)" (expt 1/64 3/2) 1/512)
756 (test-equal "expt (rat base & exponent)" (expt 1/4 1/2) 1/2)
757 (parameterize ((current-test-epsilon 1e-10))
758 (test-equal "expt (negative w/ rat exponent)" (expt -16 1/4) 1.4142135623731+1.41421356237309i))
759 (test-assert "expt" (show (expt 2 2.0)))
760 (test-assert "expt" (show (expt 2 -1)))
761 (test-equal "expt between double and 64-bit integer value"
762 (expt 999 6) 994014980014994001)
763 (parameterize ((current-test-epsilon 1e-10))
764 (test-equal "expt with complex result" (expt -1 1.5) -1.836909530733566e-16-1.0i))
765 (test-equal "exact expt with complex number" (expt 0+1i 5) 0+1i)
766 (test-equal "exact expt with complex number, real result" (expt 0+1i 6) -1)
767 (test-equal "inexact expt with complex number" (expt 0.0+1.0i 5.0) 0.0+1.0i)
768 (test-equal "inexact expt with complex number, real result" (expt 0.0+1.0i 6.0) -1.0)
769 (parameterize ((current-test-epsilon 1e-10))
770 (test-equal "inexact noninteger expt with complex number"
771 (expt 0.0+4.0i 0.5) 1.4142135623731+1.41421356237309i)
772 (test-equal "exp with complex numbers" (exp 1+i) 1.4686939399158851+2.2873552871788423i))
773
774 (test-equal "log of exp = 1" (log (exp 1)) 1.0)
775 (test-assert "log(-x) = compnum" (cplxnum? (log -2.0)))
776 (parameterize ((current-test-epsilon 1e-10))
777 (test-equal "log of -1" (log -1) 0.0+3.141592653589793i))
778 ;; XXX We should probably attempt to make this return an exact number
779 (parameterize ((current-test-epsilon 1e-10))
780 (test-equal "log(expt(2,x),2) = x" (log (expt 2 500) 2) 500.0)
781 (test-equal "log with complex number" (log +i) 0.0+1.5707963267948966i)
782
783 (test-equal "exp(log(x)) = x" (exp (log 2.0-3.0i)) 2.0-3.0i)
784 (test-equal "log(exp(x)) = x" (log (exp 2.0-3.0i)) 2.0-3.0i)
785 (test-equal "log(expt(2,x),2) = x" (log (expt 2 2.0-3.0i) 2) 2.0-3.0i))
786
787 (letrec ((fac (lambda (n)
788 (if (zero? n)
789 1
790 (* n (fac (- n 1))) ) ) ) )
791 (test-assert "bigfac" (show (fac 100)))
792 (test-equal "zero signum fixnum" (signum 0) 0)
793 (test-equal "zero signum flonum" (signum .0) 0.0)
794 (test-equal "positive signum fixnum" (signum 2) 1)
795 (test-equal "positive signum ratnum" (signum 1/2) 1)
796 (test-equal "positive signum flonum" (signum 2.0) 1.0)
797 (test-equal "positive signum bignum" (signum b1) 1)
798 (test-equal "negative signum fixnum" (signum -2) -1)
799 (test-equal "negative signum ratnum" (signum -1/2) -1)
800 (test-equal "negative signum flonum" (signum -2) -1)
801 (test-equal "negative signum bignum" (signum (- b1)) -1)
802 ;; From CLHS
803 (parameterize ((current-test-epsilon 1e-10))
804 (test-equal "positive signum compnum(1)" (signum 0+33i) 0+1i)
805 (test-equal "positive signum compnum(2)" (signum 7.5+10.0i) 0.6+0.8i)
806 (test-equal "negative signum compnum " (signum 0.0-14.7i) 0.0-1.0i)))
807 (test-equal "most-negative-fixnum + most-negative-fixnum = 2 * most-negative-fixnum"
808 (+ most-negative-fixnum most-negative-fixnum) (* 2 most-negative-fixnum))
809 (test-equal "most-negative-fixnum - most-negative-fixnum = 0"
810 (- most-negative-fixnum most-negative-fixnum) 0)
811 (test-equal "most-positive-fixnum + most-positive-fixnum = 2 * most-positive-fixnum"
812 (+ most-positive-fixnum most-positive-fixnum) (* 2 most-positive-fixnum))
813 (test-equal "most-positive-fixnum - most-positive-fixnum = 0"
814 (- most-positive-fixnum most-positive-fixnum) 0)
815)
816
817
818(test-group "R5RS"
819
820 (test-equal "+" (+ 3 4) 7)
821 (test-equal "+" (+ 3) 3)
822 (test-equal "+" (+) 0)
823 (test-equal "*" (* 4) 4)
824 (test-equal "*" (*) 1)
825
826 (test-equal "-" (- 3 4) -1)
827 (test-equal "-" (- 3 4 5) -6)
828 (test-equal "-" (- 3) -3)
829 (test-assert "/ (3/20)" (show (/ 3 4 5)))
830 (test-assert "/ (1/3)" (show (/ 3)))
831
832 (test-equal "numerator" (numerator (/ 6 4)) 3)
833 (test-equal "denominator" (denominator (/ 6 4)) 2)
834
835 (test-equal "complex?" (complex? c1) #t)
836 (test-equal "complex?" (complex? 3) #t)
837 (test-equal "real?" (real? 3) #t)
838 (test-equal "real?" (real? (make-rectangular -2.5 0.0)) #t)
839 (test-equal "real?" (real? -2+1i) #f)
840 (test-equal "real?" (real? 1e0) #t)
841 (test-equal "rational?" (rational? (/ 6 10)) #t)
842 (test-assert "check rational" (show (/ 6 3)))
843 (test-equal "rational?" (rational? (/ 6 3)) #t)
844 (test-equal "integer?" (integer? (make-rectangular 3 0)) #t)
845 (test-equal "integer?" (integer? 1+3i) #f)
846 (test-equal "integer?" (integer? 3.0) #t)
847 (test-equal "integer?" (integer? (/ 8 4)) #t)
848 (test-equal "integer?" (integer? 1/2) #f)
849 (test-equal "exact-integer?" (exact-integer? (make-rectangular 3 0)) #t)
850 (test-equal "exact-integer?" (exact-integer? 1+3i) #f)
851 (test-equal "exact-integer?" (exact-integer? 3.0) #f)
852 (test-equal "exact-integer?" (exact-integer? (/ 8 4)) #t)
853 (test-equal "exact-integer?" (exact-integer? 1/2) #f)
854
855 (test-equal "max" (max 3 4) 4)
856 (test-equal "max" (max 3.9 4) 4.0)
857
858 (test-equal "modulo" (modulo 13 4) 1)
859 (test-equal "modulo" (modulo 13.0 4) 1.0)
860 (test-equal "modulo" (modulo 13 4.0) 1.0)
861 (test-error "modulo" (modulo 13.1 4.0))
862 (test-error "modulo" (modulo 13.0 4.1))
863 (test-equal "remainder" (remainder 13 4) 1)
864 (test-error "remainder" (remainder 13.1 4.0))
865 (test-error "remainder" (remainder 13.0 4.1))
866 (test-equal "modulo" (modulo -13 4) 3)
867 (test-equal "remainder" (remainder -13 4) -1)
868 (test-equal "modulo" (modulo 13 -4) -3)
869 (test-equal "remainder" (remainder 13 -4) 1)
870 (test-equal "modulo" (modulo -13 -4) -1)
871 (test-equal "remainder" (remainder -13 -4) -1)
872 (test-equal "remainder" (remainder -13 -4.0) -1.0)
873
874 (test-assert (even? 2))
875 (test-assert (not (even? 1)))
876 (test-assert (even? -2))
877 (test-assert (not (even? -1)))
878 (test-assert (even? 2.0))
879 (test-assert (not (even? 1.0)))
880 (test-assert (even? -2.0))
881 (test-assert (not (even? -1.0)))
882 (test-error (even? 2.1))
883 (test-error (even? -2.3))
884 (test-error (even? +inf.0))
885 (test-error (even? +nan.0))
886 (test-assert (even? (* most-positive-fixnum 2)))
887 (test-assert (not (even? (+ (* most-positive-fixnum 2) 1))))
888 (test-assert (odd? (+ (* most-positive-fixnum 2) 1)))
889 (test-assert (not (odd? (* most-positive-fixnum 2))))
890 (test-error (even? 2.0+3.0i))
891 (test-error (even? 2+3i))
892 (test-error (odd? 2.0+3.0i))
893 (test-error (odd? 2+3i))
894
895 (test-equal "floor" (floor -4.3) -5.0)
896 (test-equal "ceiling" (ceiling -4.3) -4.0)
897 (test-equal "truncate" (truncate -4.3) -4.0)
898 (test-equal "round" (round -4.3) -4.0)
899 (test-equal "floor" (floor 3.5) 3.0)
900 (test-equal "ceiling" (ceiling 3.5) 4.0)
901 (test-equal "truncate" (truncate 3.5) 3.0)
902 (test-equal "round" (round 3.5) 4.0)
903 (test-equal "round" (round 4.5) 4.0)
904 (test-equal "round" (round (/ 7 2)) 4)
905 (test-equal "round" (round 7) 7)
906
907 (test-equal "rationalize (1/3)" (rationalize (inexact->exact .3) (/ 1 10)) 1/3)
908 (test-equal "rationalize (#i1/3)" (rationalize .3 (/ 1 10)) #i1/3)
909)
910
911(test-group "bitwise ops"
912
913 (test-equal "and" (bitwise-and #xff #x1) 1)
914 (test-equal "zero-arg and" (bitwise-and) -1) ; Arbitrary, but specified by srfi-33
915 (test-equal "ior" (bitwise-ior #x0f #x1) #xf)
916 (test-equal "zero-arg ior" (bitwise-ior) 0) ; Same
917 (test-equal "xor" (bitwise-xor #x0f #x1) 14)
918 (test-equal "zero-arg xor" (bitwise-xor) 0) ; Same
919 (test-assert "not" (show (bitwise-not #x0f)))
920 (test-error (bitwise-and 'x))
921 (test-error (bitwise-xor 'x))
922 (test-error (bitwise-ior 'x))
923 (test-error (bitwise-and 1 'x))
924 (test-error (bitwise-xor 1 'x))
925 (test-error (bitwise-ior 1 'x))
926 (test-error (bit->boolean 1 -1))
927 (test-error (bit->boolean b1 -1))
928 (test-error (bit->boolean 1 1.0))
929 (test-error (bit->boolean 1.0 1))
930 (test-equal (bit->boolean -1 b1) #t)
931 (test-equal (bit->boolean 0 b1) #f)
932 (test-equal (bit->boolean 5 2) #t)
933 (test-equal (bit->boolean 5 0) #t)
934 (test-equal (bit->boolean 5 1) #f)
935 (test-equal (bit->boolean -2 0) #f)
936 (test-equal (bit->boolean -2 1) #t)
937 (test-equal (bit->boolean (expt -2 63) 256) #t)
938 (test-equal (bit->boolean (expt 2 63) 256) #f)
939 (test-equal (arithmetic-shift 15 2) 60)
940 (test-equal (arithmetic-shift 15 -2) 3)
941 (test-equal (arithmetic-shift -15 2) -60)
942 (test-equal (arithmetic-shift -15 -2) -4) ; 2's complement
943 (test-equal (arithmetic-shift -31 most-negative-fixnum) -1)
944 (test-equal (arithmetic-shift 31 most-negative-fixnum) 0)
945 (test-equal (arithmetic-shift b1 0) b1)
946 (test-equal (arithmetic-shift (arithmetic-shift b1 -1) 1) b1)
947 (test-error (arithmetic-shift 0.1 2))
948 ;; XXX Do the following two need to fail? Might as well use the integral value
949 (test-error (arithmetic-shift #xf 2.0))
950 (test-error (arithmetic-shift #xf -2.0))
951 (test-error (arithmetic-shift #xf 2.1))
952 (test-error (arithmetic-shift #xf -2.1))
953 (test-error (arithmetic-shift +inf.0 2))
954 (test-error (arithmetic-shift +nan.0 2))
955 (when 64-bits?
956 (test-equal (arithmetic-shift (expt 2 31) (- (expt 2 31))) 0))
957
958 ;; by Jeremy Sydik
959 (let ((leftrot32
960 (lambda (value amount)
961 (let ((shifted (arithmetic-shift value amount)))
962 (let ((anded (bitwise-and #xFFFFFFFF shifted)))
963 (bitwise-ior anded
964 (arithmetic-shift shifted -32)))) )))
965 (test-equal "leftrot32 28" (leftrot32 1 28) 268435456)
966 (test-equal "leftrot32 29" (leftrot32 1 29) 536870912)
967 (test-equal "leftrot32 30" (leftrot32 1 30) 1073741824))
968)
969
970(test-group "string conversion"
971
972 (test-assert "fix" (number->string 123))
973 (test-assert "fix/base" (number->string 123 16))
974 (test-assert "flo" (number->string 99.2))
975 (test-assert "big" (number->string b1))
976 (test-assert "big/base" (number->string b1 2))
977 (test-assert "rat" (number->string r1))
978 (test-assert "comp" (number->string c1))
979
980 (test-equal "edge case printing"
981 (number->string (expt 2 256) 16)
982 "10000000000000000000000000000000000000000000000000000000000000000")
983 (test-equal "non-exact multiple of 64 length edge case printing"
984 "4000000000000000000000" (number->string (expt 2 65) 8))
985 (test-equal "another non-exact multiple of 64 length edge case printing"
986 "200000000000000000000000" (number->string (expt 2 70) 8))
987 (test-equal "edge case length calculation"
988 "10000000000000000000000000000000000000000000000000000000000000000000000" (number->string (expt 2 210) 8))
989 (test-equal "positive hexdigit invariance"
990 (number->string
991 (string->number "123456789abcdef123456789abcdef123456789abcdef" 16)
992 16)
993 "123456789abcdef123456789abcdef123456789abcdef")
994 (test-equal "negative hexdigit invariance"
995 (number->string
996 (string->number "-123456789abcdef123456789abcdef123456789abcdef" 16)
997 16)
998 "-123456789abcdef123456789abcdef123456789abcdef")
999
1000 (test-equal "fix" (string->number "123") 123)
1001 (test-equal "fix/base" (string->number "ff" 16) 255)
1002 (test-equal "fix/base-o" (string->number "16" 8) 14)
1003 (test-equal "fix/unusual-base" (string->number "1234" 5) 194)
1004 (test-equal "fix/wrong-base" (string->number "1234" 4) #f)
1005 (test-error "fix/invalid-base" (string->number "1234" 0))
1006 (test-error "fix/invalid-base" (string->number "1234" 1))
1007 (test-equal "embedded base overrides supplied base" (string->number "#x10" 10) 16)
1008 (test-equal "flo" (string->number "123.23") 123.23)
1009 (test-equal "flo2" (string->number "1e2") 100.0)
1010 (test-assert "big" (show (string->number "123873487384737447")))
1011 (test-assert "big/neg" (show (string->number "-123873487384737447")))
1012 (test-assert "big/pos" (show (string->number "+123873487384737447")))
1013 (test-assert "rat" (show (string->number "123/456")))
1014 (test-assert "rat/neg" (show (string->number "-123/456")))
1015 (test-assert "rat/pos" (show (string->number "+123/456")))
1016 (test-assert "rat2" (show (string->number "#o123/456")))
1017 (test-equal "rat/inexact" (show (string->number "#i123/456")) (/ 123.0 456))
1018 (test-equal "invalid rat" (string->number "123/0") #f)
1019 (test-assert "comp" (show (string->number "+12i")))
1020 (test-assert "comp" (show (string->number "12+34i")))
1021 (test-assert "comp" (show (string->number "-i")))
1022 (test-assert "comp" (show (string->number "99@55")))
1023 (test-assert "comp" (show (string->number "1/2@3/4")))
1024 (test-assert "comp2" (show (string->number "#x99+55i")))
1025 ;; This is to check for a silly problem cause by representing numbers exactly
1026 ;; all the way until the end, then converting to inexact. This "silly problem"
1027 ;; could probably be exploited in a resource consumption attack.
1028 (let* ((t1 (current-seconds))
1029 (i1 (string->number "1e1000000"))
1030 (i2 (string->number "1.0e1000000"))
1031 (e1 (string->number "#e1e1000000"))
1032 (e2 (string->number "#e1.0e1000000"))
1033 (t2 (current-seconds)))
1034 (test-assert "read time for inexacts with large positive exp isn't insanely high" (< (- t2 t1) 2))
1035 (test-equal "inexact read back are equal" i2 i1)
1036 (test-equal "inexact are inf" +inf.0 i1)
1037 (test-equal "exact are equal" e2 e1)
1038 (test-equal "exact are false" #f e1))
1039 (let* ((t1 (current-seconds))
1040 (i1 (string->number "-1e1000000"))
1041 (i2 (string->number "-1.0e1000000"))
1042 (e1 (string->number "#e-1e1000000"))
1043 (e2 (string->number "#e-1.0e1000000"))
1044 (t2 (current-seconds)))
1045 (test-assert "read time for inexacts with large positive exp isn't insanely high" (< (- t2 t1) 2))
1046 (test-equal "negative inexact read back are equal" i2 i1)
1047 (test-equal "negative inexact are negative inf" -inf.0 i1)
1048 (test-equal "negative exact are equal" e2 e1)
1049 (test-equal "negative exact are false" #f e1))
1050 (let* ((t1 (current-seconds))
1051 (i1 (string->number "1e-1000000"))
1052 (i2 (string->number "1.0e-1000000"))
1053 (e1 (string->number "#e1e-1000000"))
1054 (e2 (string->number "#e1.0e-1000000"))
1055 (t2 (current-seconds)))
1056 (test-assert "read time for inexacts with large negative exp isn't insanely high" (< (- t2 t1) 2))
1057 (test-equal "inexact read back are equal" i2 i1)
1058 (test-equal "inexact are 0" +0.0 i1)
1059 (test-equal "exact are equal" e2 e1)
1060 (test-equal "exact are false" #f e1))
1061
1062 (test-group "read/write invariance of simple integers for different radices"
1063 (let lp ((radix 2)
1064 (digit 0))
1065 (cond ((= digit radix) (lp (add1 radix) 0))
1066 ((<= radix 36)
1067 (let* ((char (string-ref (number->string digit radix) 0))
1068 (str (make-string 10 char)))
1069 (test-equal (sprintf "radix ~A digits ~S" radix digit)
1070 (number->string (string->number str) radix)
1071 (if (char=? char #\0) "0" str)))))))
1072)
1073
1074(test-group "non-standard type procedures"
1075
1076 (test-equal "fixnum" (fixnum? max-fix) #t)
1077
1078 (test-equal "bignum" (bignum? b1) #t)
1079 (test-equal "bignum" (bignum? min-big) #t)
1080
1081 (test-equal "ratnum" (ratnum? r1) #t)
1082
1083 (test-equal "nan: fix" (nan? 1) #f)
1084 (test-equal "nan: flo" (nan? 1.0) #f)
1085 (test-equal "nan: +inf" (nan? (/ 1.0 0.0)) #f)
1086 (test-equal "nan: -inf" (nan? (/ -1.0 0.0)) #f)
1087 (test-equal "nan: nan" (nan? (/ 0.0 0.0)) #t)
1088 (test-equal "nan: nan+nani" (nan? (make-rectangular (/ 0.0 0.0) (/ 0.0 0.0))) #t)
1089 (test-equal "nan: flo+nani" (nan? (make-rectangular 1.0 (/ 0.0 0.0))) #t)
1090 (test-equal "nan: nan+floi" (nan? (make-rectangular (/ 0.0 0.0) 1.0)) #t)
1091 (test-error "nan: no number" (nan? 'x))
1092
1093 (test-equal "finite: fix" (finite? 1) #t)
1094 (test-equal "finite: flo" (finite? 1.0) #t)
1095 (test-equal "finite: +inf" (finite? (/ 1.0 0.0)) #f)
1096 (test-equal "finite: -inf" (finite? (/ 1.0 0.0)) #f)
1097 (test-equal "finite: nan" (finite? (/ 0.0 0.0)) #f)
1098 (test-equal "finite: nan+floi" (finite? (make-rectangular (/ 0.0 0.0) 1.0)) #f)
1099 (test-equal "finite: inf+infi" (finite? (make-rectangular (/ 1.0 0.0) (/ 1.0 0.0))) #f)
1100 (test-equal "finite: flo+infi" (finite? (make-rectangular 1.0 (/ 1.0 0.0))) #f)
1101 (test-equal "finite: inf+floi" (finite? (make-rectangular (/ 1.0 0.0) 1.0)) #f)
1102 (test-error "finite: no number" (finite? 'x))
1103
1104 (test-equal "infinite: fix" (infinite? 1) #f)
1105 (test-equal "infinite: flo" (infinite? 1.0) #f)
1106 (test-equal "infinite: +inf" (infinite? (/ 1.0 0.0)) #t)
1107 (test-equal "infinite: -inf" (infinite? (/ 1.0 0.0)) #t)
1108 (test-equal "infinite: nan" (infinite? (/ 0.0 0.0)) #f)
1109 (test-equal "infinite: inf+infi" (infinite? (make-rectangular (/ 1.0 0.0) (/ 1.0 0.0))) #t)
1110 (test-equal "infinite: flo+infi" (infinite? (make-rectangular 1.0 (/ 1.0 0.0))) #t)
1111 (test-equal "infinite: inf+floi" (infinite? (make-rectangular (/ 1.0 0.0) 1.0)) #t)
1112 (test-error "infinite: no number" (infinite? 'x))
1113
1114 (test-equal "cplxnum: compintintnum" (cplxnum? c1) #t)
1115 (test-equal "cplxnum: compintflointnum" (cplxnum? 1.0+1i) #t)
1116 (test-equal "cplxnum: compflointnum" (cplxnum? c2) #t)
1117 (test-equal "cplxnum: compfloflonum" (cplxnum? 3.4-4.3i) #t)
1118 (test-equal "not cplxnum: fixnum" (cplxnum? 1) #f)
1119)
1120
1121;; The usual comparator doesn't work, because zero or a very small number
1122;; is many times any other small number, but the absolute difference should
1123;; be minimal, so we compare for that instead.
1124(parameterize ((current-test-epsilon 1e-9)
1125 (current-test-comparator
1126 (lambda (exp act)
1127 (or (and (nan? exp) (nan? act))
1128 (and (< (abs (- (real-part exp) (real-part act)))
1129 (current-test-epsilon))
1130 (< (abs (- (imag-part exp) (imag-part act)))
1131 (current-test-epsilon)))))))
1132
1133 ;; We're using (acos (cos x)) instead of just (acos y) because we want
1134 ;; to test the compiler's specialization rules of cos output.
1135
1136 (test-group "trigonometric functions"
1137 (test-group "flonums"
1138 ;; Note: we don't *actually* distinguish -nan from +nan, but whatever :)
1139 (test-equal "acos(-inf)" (acos -inf.0) -nan.0)
1140 (test-equal "acos(<small number>)" (acos -1e100) -nan.0)
1141 (test-equal "cos(-1/3pi)" (cos (- (/ pi 3))) 0.5)
1142 (test-equal "acos(cos(-1/3pi))" (acos (cos (- (/ pi 3)))) (/ pi 3))
1143 (test-equal "cos(-1/4pi)" (cos (- (/ pi 4))) 0.7071067811865476)
1144 (test-equal "acos(cos(-1/4pi))" (acos (cos (- (/ pi 4)))) (/ pi 4))
1145 (test-equal "cos(-1/2pi)" (cos (- (/ pi 2))) 0.0)
1146 (test-equal "acos(cos(-1/2pi))" (acos (cos (- (/ pi 2)))) (/ pi 2))
1147 (test-equal "cos(-pi)" (cos (- pi)) -1.0)
1148 (test-equal "acos(cos(-pi))" (acos (cos (- pi))) pi)
1149 (test-equal "cos(0)" (cos 0.0) 1.0)
1150 (test-equal "acos(cos(0))" (acos (cos 0.0)) 0.0)
1151 (test-equal "cos( 1/4pi)" (cos (/ pi 4)) 0.7071067811865476)
1152 (test-equal "acos(cos( 1/4pi))" (acos (cos (/ pi 4))) (/ pi 4))
1153 (test-equal "cos( 1/3pi)" (cos (/ pi 3)) 0.5)
1154 (test-equal "acos(cos( 1/3pi))" (acos (cos (/ pi 3))) (/ pi 3))
1155 (test-equal "cos( 1/2pi)" (cos (/ pi 2)) 0.0)
1156 (test-equal "acos(cos( 1/2pi))" (acos (cos (/ pi 2))) (/ pi 2))
1157 (test-equal "cos( 2/3pi)" (cos (/ (* 2 pi) 3)) -0.5)
1158 (test-equal "acos(cos( 2/3pi))" (acos (cos (/ (* 2 pi) 3))) (/ (* 2 pi) 3))
1159 (test-equal "cos( 3/4pi)" (cos (* (/ pi 4) 3)) -0.7071067811865476)
1160 (test-equal "acos(cos( 3/4pi))" (acos (cos (* (/ pi 4) 3))) (* (/ pi 4) 3))
1161 (test-equal "cos( pi)" (cos pi) -1.0)
1162 (test-equal "acos(cos( pi))" (acos (cos pi)) pi)
1163 (test-equal "cos( 3/2pi)" (cos (+ pi (/ pi 2))) 0.0)
1164 (test-equal "acos(cos( 3/2pi))" (acos (cos (+ pi (/ pi 2)))) (/ pi 2))
1165 (test-equal "cos( 4/3pi)" (cos (+ pi (/ pi 3))) -0.5)
1166 (test-equal "acos(cos( 4/3pi))" (acos (cos (+ pi (/ pi 3)))) (* 2 (/ pi 3)))
1167 (test-equal "cos( 5/4pi)" (cos (+ pi (/ pi 4))) -0.7071067811865476)
1168 (test-equal "acos(cos( 5/4pi))" (acos (cos (+ pi (/ pi 4)))) (* 3 (/ pi 4)))
1169 (test-equal "cos( 2pi)" (cos (* 2 pi)) 1.0)
1170 (test-equal "acos(cos( 2pi))" (acos (cos (* 2 pi))) 0)
1171 (test-equal "acos(pi)" (acos pi) 0.0+1.81152627246085i)
1172 (test-equal "acos(+inf)" (acos +inf.0) -nan.0)
1173
1174 (test-equal "asin(-inf)" (asin -inf.0) -nan.0)
1175 (test-equal "asin(<small number>)" (asin -1e100) -nan.0)
1176 (test-equal "sin(-1/3pi)" (sin (- (/ pi 3))) -0.8660254037844386)
1177 (test-equal "asin(sin(-1/3pi))" (asin (sin (- (/ pi 3)))) (- (/ pi 3)))
1178 (test-equal "sin(-1/4pi)" (sin (- (/ pi 4))) -0.7071067811865476)
1179 (test-equal "asin(sin(-1/4pi))" (asin (sin (- (/ pi 4)))) (- (/ pi 4)))
1180 (test-equal "sin(-1/2pi)" (sin (- (/ pi 2))) -1.0)
1181 (test-equal "asin(sin(-1/2pi))" (asin (sin (- (/ pi 2)))) (- (/ pi 2)))
1182 (test-equal "sin(-pi)" (sin (- pi)) 0.0)
1183 (test-equal "asin(sin(-pi))" (asin (sin (- pi))) 0.0)
1184 (test-equal "sin(0)" (sin 0.0) 0.0)
1185 (test-equal "asin(sin(0))" (asin (sin 0.0)) 0.0)
1186 (test-equal "sin( 1/4pi)" (sin (/ pi 4)) 0.7071067811865476)
1187 (test-equal "asin(sin( 1/4pi))" (asin (sin (/ pi 4))) (/ pi 4))
1188 (test-equal "sin( 1/3pi)" (sin (/ pi 3)) 0.8660254037844386)
1189 (test-equal "asin(sin( 1/3pi))" (asin (sin (/ pi 3))) (/ pi 3))
1190 (test-equal "sin( 1/2pi)" (sin (/ pi 2)) 1.0)
1191 (test-equal "asin(sin( 1/2pi))" (asin (sin (/ pi 2))) (/ pi 2))
1192 (test-equal "sin( 2/3pi)" (sin (/ (* 2 pi) 3)) 0.8660254037844386)
1193 (test-equal "asin(sin( 2/3pi))" (asin (sin (/ (* 2 pi) 3))) (/ pi 3))
1194 (test-equal "sin( 3/4pi)" (sin (* (/ pi 4) 3)) 0.7071067811865476)
1195 (test-equal "asin(sin( 3/4pi))" (asin (sin (* (/ pi 4) 3))) (/ pi 4))
1196 (test-equal "sin( pi)" (sin pi) 0.0)
1197 (test-equal "asin(sin( pi))" (asin (sin pi)) 0.0)
1198 (test-equal "sin( 3/2pi)" (sin (+ pi (/ pi 2))) -1.0)
1199 (test-equal "asin(sin( 3/2pi))" (asin (sin (+ pi (/ pi 2)))) (- (/ pi 2)))
1200 (test-equal "sin( 4/3pi)" (sin (+ pi (/ pi 3))) -0.8660254037844386)
1201 (test-equal "asin(sin( 4/3pi))" (asin (sin (+ pi (/ pi 3)))) (- (/ pi 3)))
1202 (test-equal "sin( 5/4pi)" (sin (+ pi (/ pi 4))) -0.7071067811865476)
1203 (test-equal "asin(sin( 5/4pi))" (asin (sin (+ pi (/ pi 4)))) (- (/ pi 4)))
1204 (test-equal "sin( 2pi)" (sin (* 2 pi)) 0.0)
1205 (test-equal "asin(sin( 2pi))" (asin (sin (* 2 pi))) 0.0)
1206 (test-equal "asin(pi)" (asin pi) 1.57079632679490-1.81152627246085i)
1207 (test-equal "asin(+inf)" (asin +inf.0) -nan.0)
1208
1209 (test-equal "atan(-inf)" (atan -inf.0) (- (/ pi 2)))
1210 (test-equal "atan(<small number>)" (atan -1e100) (- (/ pi 2)))
1211 (test-equal "tan(-1/3pi)" (tan (- (/ pi 3))) -1.7320508075688773)
1212 (test-equal "atan(tan(-1/3pi))" (atan (tan (- (/ pi 3)))) (- (/ pi 3)))
1213 (test-equal "tan(-1/4pi)" (tan (- (/ pi 4))) -1.0)
1214 (test-equal "atan(tan(-1/4pi))" (atan (tan (- (/ pi 4)))) (- (/ pi 4)))
1215 ;; NOTE: tan(-(/ pi 2)) should be -inf(?), but isn't. Is that a bug?
1216 (test-equal "tan(-pi)" (tan (- pi)) 0.0)
1217 (test-equal "atan(tan(-pi))" (atan (tan (- pi))) 0.0)
1218 (test-equal "tan(0)" (tan 0.0) 0.0)
1219 (test-equal "atan(tan(0))" (atan (tan 0.0)) 0.0)
1220 (test-equal "tan( 1/4pi)" (tan (/ pi 4)) 1.0)
1221 (test-equal "atan(tan( 1/4pi))" (atan (tan (/ pi 4))) (/ pi 4))
1222 (test-equal "tan( 1/3pi)" (tan (/ pi 3)) 1.7320508075688773)
1223 (test-equal "atan(tan( 1/3pi))" (atan (tan (/ pi 3))) (/ pi 3))
1224 (test-equal "tan( 2/3pi)" (tan (/ (* 2 pi) 3)) -1.7320508075688773)
1225 (test-equal "atan(tan( 2/3pi))" (atan (tan (/ (* 2 pi) 3))) (- (/ pi 3)))
1226 (test-equal "tan( 3/4pi)" (tan (* (/ pi 4) 3)) -1.0)
1227 (test-equal "atan(tan( 3/4pi))" (atan (tan (* (/ pi 4) 3))) (- (/ pi 4)))
1228 (test-equal "tan( pi)" (tan pi) 0.0)
1229 (test-equal "atan(tan( pi))" (atan (tan pi)) 0.0)
1230 (test-equal "tan( 4/3pi)" (tan (+ pi (/ pi 3))) 1.7320508075688773)
1231 (test-equal "atan(tan( 4/3pi))" (atan (tan (+ pi (/ pi 3)))) (/ pi 3))
1232 (test-equal "tan( 5/4pi)" (tan (+ pi (/ pi 4))) 1.0)
1233 (test-equal "atan(tan( 5/4pi))" (atan (tan (+ pi (/ pi 4)))) (/ pi 4))
1234 (test-equal "tan( 2pi)" (tan (* 2 pi)) 0.0)
1235 (test-equal "atan(tan( 2pi))" (atan (tan (* 2 pi))) 0.0)
1236 (test-equal "atan(pi)" (atan 1e100) (/ pi 2))
1237 (test-equal "atan(+inf)" (atan +inf.0) (/ pi 2))
1238
1239 (test-equal "atan2(3, tan(pi))" (atan 3 (tan pi)) (/ pi 2))
1240 (test-equal "atan2(3, -tan(pi))" (atan 3 (- (tan pi))) (/ pi 2))
1241 (test-equal "atan2(-3, tan(pi))" (atan -3 (tan pi)) (- (/ pi 2)))
1242 (test-equal "atan2(-3, -tan(pi))" (atan -3 (- (tan pi))) (- (/ pi 2)))
1243 ;; Equivalence described in R5RS
1244 (test-equal "atan2(1, 2) = angle(2+i)"
1245 (angle (make-rectangular 2 1)) (atan 1 2))
1246 (test-equal "atan2(1, b1) = angle(2+i)"
1247 (angle (make-rectangular b1 1)) (atan 1 b1))
1248 (test-equal "atan2(b1, 1) = angle(2+i)"
1249 (angle (make-rectangular 1 b1)) (atan b1 1))
1250 (test-equal "atan2(-0.1, 3.2) = angle(3.2-0.1i)"
1251 (angle (make-rectangular 3.2 -0.1)) (atan -0.1 3.2))
1252 )
1253
1254 ;; Cross-checked against Gauche and Scheme48's output
1255 (test-group "compnums"
1256 (test-equal "cos(0.0+1.0i)" (cos (make-rectangular 0.0 1.0))
1257 1.5430806348152437)
1258 (test-equal "acos(cos(0.0+1.0i))" (acos (cos (make-rectangular 0.0 1.0)))
1259 0.0+1.0i)
1260 (test-equal "cos(0.0-1.0i)" (cos (make-rectangular 0.0 -1.0))
1261 1.5430806348152437)
1262 (test-equal "acos(cos(0.0-1.0i))" (acos (cos (make-rectangular 0.0 -1.0)))
1263 0.0+1.0i)
1264 (test-equal "cos(0.0+3.0i)" (cos (make-rectangular 0.0 3.0))
1265 10.067661995777765)
1266 (test-equal "acos(cos(0.0+3.0i))" (acos (cos (make-rectangular 0.0 3.0)))
1267 0.0+3.0i)
1268 (test-equal "cos(0.0-3.0i)" (cos (make-rectangular 0.0 -3.0))
1269 10.067661995777765)
1270 (test-equal "acos(cos(0.0-3.0i))" (acos (cos (make-rectangular 0.0 -3.0)))
1271 0.0+3.0i)
1272 (test-equal "cos(0.5+0.5i)"
1273 (cos (make-rectangular 0.5 0.5))
1274 (make-rectangular 0.9895848833999199 -0.24982639750046154))
1275 (test-equal "acos(cos(0.5+0.5i))"
1276 (acos (cos (make-rectangular 0.5 0.5)))
1277 (make-rectangular 0.5 0.5))
1278 (test-equal "cos(0.5-0.5i)"
1279 (cos (make-rectangular 0.5 -0.5))
1280 (make-rectangular 0.9895848833999199 0.24982639750046154))
1281 (test-equal "acos(cos(0.5-0.5i))"
1282 (acos (cos (make-rectangular 0.5 -0.5)))
1283 (make-rectangular 0.5 -0.5))
1284 (test-equal "cos(-0.5-0.5i)"
1285 (cos (make-rectangular -0.5 -0.5))
1286 (make-rectangular 0.9895848833999199 -0.24982639750046154))
1287 (test-equal "acos(cos(-0.5-0.5i))"
1288 (acos (cos (make-rectangular -0.5 -0.5)))
1289 (make-rectangular 0.5 0.5))
1290 (test-equal "cos(-0.5+0.5i)"
1291 (cos (make-rectangular -0.5 0.5))
1292 (make-rectangular 0.9895848833999199 0.24982639750046154))
1293 (test-equal "acos(cos(-0.5+0.5i))"
1294 (acos (cos (make-rectangular -0.5 0.5)))
1295 (make-rectangular 0.5 -0.5))
1296 (test-equal "cos(-1.0+1.0i)"
1297 (cos (make-rectangular -1.0 1.0))
1298 (make-rectangular 0.8337300251311491 0.9888977057628651))
1299 (test-equal "acos(cos(-1.0+1.0i))"
1300 (acos (cos (make-rectangular -1.0 1.0)))
1301 (make-rectangular 1.0 -1.0))
1302 (test-equal "cos(-1.0-1.0i)"
1303 (cos (make-rectangular -1.0 -1.0))
1304 (make-rectangular 0.8337300251311491 -0.9888977057628651))
1305 (test-equal "acos(cos(-1.0-1.0i))"
1306 (acos (cos (make-rectangular -1.0 -1.0)))
1307 (make-rectangular 1.0 1.0))
1308 (test-equal "cos(1.0-1.0i)"
1309 (cos (make-rectangular 1.0 -1.0))
1310 (make-rectangular 0.8337300251311491 0.9888977057628651))
1311 (test-equal "acos(cos(1.0-1.0i))"
1312 (acos (cos (make-rectangular 1.0 -1.0)))
1313 (make-rectangular 1.0 -1.0))
1314 (test-equal "cos(1.0+1.0i)"
1315 (cos (make-rectangular 1.0 1.0))
1316 (make-rectangular 0.8337300251311491 -0.9888977057628651))
1317 (test-equal "acos(cos(1.0+1.0i))"
1318 (acos (cos (make-rectangular 1.0 1.0)))
1319 (make-rectangular 1.0 1.0))
1320 (test-equal "cos(2.0+3.0i)"
1321 (cos (make-rectangular 2.0 3.0))
1322 (make-rectangular -4.189625690968807 -9.109227893755337))
1323 (test-equal "acos(cos(2.0+3.0i))"
1324 (acos (cos (make-rectangular 2.0 3.0)))
1325 (make-rectangular 2.0 3.0))
1326 (test-equal "cos(-2.0+3.0i)"
1327 (cos (make-rectangular -2.0 3.0))
1328 (make-rectangular -4.189625690968807 9.109227893755337))
1329 (test-equal "acos(cos(-2.0+3.0i))"
1330 (acos (cos (make-rectangular -2.0 3.0)))
1331 (make-rectangular 2.0 -3.0))
1332 (test-equal "cos(-2.0-3.0i)"
1333 (cos (make-rectangular -2.0 -3.0))
1334 (make-rectangular -4.189625690968807 -9.109227893755337))
1335 (test-equal "acos(cos(-2.0-3.0i))"
1336 (acos (cos (make-rectangular -2.0 -3.0)))
1337 (make-rectangular 2.0 3.0))
1338 (test-equal "cos(2.0-3.0i)"
1339 (cos (make-rectangular 2.0 -3.0))
1340 (make-rectangular -4.189625690968807 9.109227893755337))
1341 (test-equal "acos(cos(2.0-3.0i))"
1342 (acos (cos (make-rectangular 2.0 -3.0)))
1343 (make-rectangular 2.0 -3.0))
1344 ;; Specialization check
1345 (test-equal "cos(acos(2.0-3.0i))"
1346 (cos (acos (make-rectangular 2.0 -3.0)))
1347 (make-rectangular 2.0 -3.0))
1348
1349 (test-equal "sin(0.0+1.0i)"
1350 (sin (make-rectangular 0.0 1.0))
1351 (make-rectangular 0.0 1.1752011936438014))
1352 (test-equal "asin(sin(0.0+1.0i))"
1353 (asin (sin (make-rectangular 0.0 1.0)))
1354 (make-rectangular 0.0 1.0))
1355 (test-equal "sin(0.0-1.0i)"
1356 (sin (make-rectangular 0.0 -1.0))
1357 (make-rectangular 0.0 -1.1752011936438014))
1358 (test-equal "asin(sin(0.0-1.0i))"
1359 (asin (sin (make-rectangular 0.0 -1.0)))
1360 (make-rectangular 0.0 -1.0))
1361 (test-equal "sin(0.0+3.0i)"
1362 (sin (make-rectangular 0.0 3.0))
1363 (make-rectangular 0.0 10.017874927409903))
1364 (test-equal "asin(sin(0.0+3.0i))"
1365 (asin (sin (make-rectangular 0.0 3.0)))
1366 (make-rectangular 0.0 3.0))
1367 (test-equal "sin(0.0-3.0i)"
1368 (sin (make-rectangular 0.0 -3.0))
1369 (make-rectangular 0.0 -10.017874927409903))
1370 (test-equal "asin(sin(0.0-3.0i))"
1371 (asin (sin (make-rectangular 0.0 -3.0)))
1372 (make-rectangular 0.0 -3.0))
1373 (test-equal "sin(0.5+0.5i)"
1374 (sin (make-rectangular 0.5 0.5))
1375 (make-rectangular 0.5406126857131534 0.4573041531842493))
1376 (test-equal "asin(sin(0.5+0.5i))"
1377 (asin (sin (make-rectangular 0.5 0.5)))
1378 (make-rectangular 0.5 0.5))
1379 (test-equal "sin(0.5-0.5i)"
1380 (sin (make-rectangular 0.5 -0.5))
1381 (make-rectangular 0.5406126857131534 -0.4573041531842493))
1382 (test-equal "asin(sin(0.5-0.5i))"
1383 (asin (sin (make-rectangular 0.5 -0.5)))
1384 (make-rectangular 0.5 -0.5))
1385 (test-equal "sin(-0.5-0.5i)"
1386 (sin (make-rectangular -0.5 -0.5))
1387 (make-rectangular -0.5406126857131534 -0.4573041531842493))
1388 (test-equal "asin(sin(-0.5-0.5i))"
1389 (asin (sin (make-rectangular -0.5 -0.5)))
1390 (make-rectangular -0.5 -0.5))
1391 (test-equal "sin(-0.5+0.5i)"
1392 (sin (make-rectangular -0.5 0.5))
1393 (make-rectangular -0.5406126857131534 +0.457304153184249))
1394 (test-equal "asin(sin(-0.5+0.5i))"
1395 (asin (sin (make-rectangular -0.5 0.5)))
1396 (make-rectangular -0.5 +0.5))
1397 (test-equal "sin(-1.0+1.0i)"
1398 (sin (make-rectangular -1.0 1.0))
1399 (make-rectangular -1.2984575814159773 0.6349639147847361))
1400 (test-equal "asin(sin(-1.0+1.0i))"
1401 (asin (sin (make-rectangular -1.0 1.0)))
1402 (make-rectangular -1.0 1.0))
1403 (test-equal "sin(-1.0-1.0i)"
1404 (sin (make-rectangular -1.0 -1.0))
1405 (make-rectangular -1.2984575814159773 -0.6349639147847361))
1406 (test-equal "asin(sin(-1.0-1.0i))"
1407 (asin (sin (make-rectangular -1.0 -1.0)))
1408 (make-rectangular -1.0 -1.0))
1409 (test-equal "sin(1.0-1.0i)"
1410 (sin (make-rectangular 1.0 -1.0))
1411 (make-rectangular 1.2984575814159773 -0.6349639147847361))
1412 (test-equal "asin(sin(1.0-1.0i))"
1413 (asin (sin (make-rectangular 1.0 -1.0)))
1414 (make-rectangular 1.0 -1.0))
1415 (test-equal "sin(2.0+3.0i)"
1416 (sin (make-rectangular 2.0 3.0))
1417 (make-rectangular 9.15449914691143 -4.168906959966565))
1418 (test-equal "asin(sin(2.0+3.0i))"
1419 (asin (sin (make-rectangular 2.0 3.0)))
1420 (make-rectangular 1.1415926535898042 -3.0))
1421 (test-equal "sin(-2.0+3.0i)"
1422 (sin (make-rectangular -2.0 3.0))
1423 (make-rectangular -9.15449914691143 -4.168906959966565))
1424 (test-equal "asin(sin(-2.0+3.0i))"
1425 (asin (sin (make-rectangular -2.0 3.0)))
1426 (make-rectangular -1.1415926535898042 -3.0))
1427 (test-equal "sin(-2.0-3.0i)"
1428 (sin (make-rectangular -2.0 -3.0))
1429 (make-rectangular -9.15449914691143 4.168906959966565))
1430 (test-equal "asin(sin(-2.0-3.0i))"
1431 (asin (sin (make-rectangular -2.0 -3.0)))
1432 (make-rectangular -1.1415926535898042 3.0))
1433 (test-equal "sin(2.0-3.0i)"
1434 (sin (make-rectangular 2.0 -3.0))
1435 (make-rectangular 9.15449914691143 4.168906959966565))
1436 (test-equal "asin(sin(2.0-3.0i))"
1437 (asin (sin (make-rectangular 2.0 -3.0)))
1438 (make-rectangular 1.1415926535898042 3.0))
1439 ;; Specialization check
1440 (test-equal "sin(asin(1.1415926535898042+3.0i))"
1441 (sin (asin (make-rectangular 2.0 3.0)))
1442 (make-rectangular 2.0 3.0))
1443
1444 (test-equal "tan(0.0+1.0i)"
1445 (tan (make-rectangular 0.0 1.0))
1446 (make-rectangular 0.0 0.7615941559557649))
1447 (test-equal "atan(tan(0.0+1.0i))"
1448 (atan (tan (make-rectangular 0.0 1.0)))
1449 (make-rectangular 0.0 1.0))
1450 (test-equal "tan(0.0-1.0i)"
1451 (tan (make-rectangular 0.0 -1.0))
1452 (make-rectangular 0.0 -0.7615941559557649))
1453 (test-equal "atan(tan(0.0-1.0i))"
1454 (atan (tan (make-rectangular 0.0 -1.0)))
1455 (make-rectangular 0.0 -1.0))
1456 (test-equal "tan(0.0+3.0i)"
1457 (tan (make-rectangular 0.0 3.0))
1458 (make-rectangular 0.0 0.9950547536867306))
1459 (test-equal "atan(tan(0.0+3.0i))"
1460 (atan (tan (make-rectangular 0.0 3.0)))
1461 (make-rectangular 0.0 3.0))
1462 (test-equal "tan(0.0-3.0i)"
1463 (tan (make-rectangular 0.0 -3.0))
1464 (make-rectangular 0.0 -0.9950547536867306))
1465 (test-equal "atan(tan(0.0-3.0i))"
1466 (atan (tan (make-rectangular 0.0 -3.0)))
1467 (make-rectangular 0.0 -3.0))
1468 (test-equal "tan(0.5+0.5i)"
1469 (tan (make-rectangular 0.5 0.5))
1470 (make-rectangular 0.4038964553160257 0.5640831412674985))
1471 (test-equal "atan(tan(0.5+0.5i))"
1472 (atan (tan (make-rectangular 0.5 0.5)))
1473 (make-rectangular 0.5 0.5))
1474 (test-equal "tan(0.5-0.5i)"
1475 (tan (make-rectangular 0.5 -0.5))
1476 (make-rectangular 0.4038964553160257 -0.5640831412674985))
1477 (test-equal "atan(tan(0.5-0.5i))"
1478 (atan (tan (make-rectangular 0.5 -0.5)))
1479 (make-rectangular 0.5 -0.5))
1480 (test-equal "tan(-0.5-0.5i)"
1481 (tan (make-rectangular -0.5 -0.5))
1482 (make-rectangular -0.4038964553160257 -0.5640831412674985))
1483 (test-equal "atan(tan(-0.5-0.5i))"
1484 (atan (tan (make-rectangular -0.5 -0.5)))
1485 (make-rectangular -0.5 -0.5))
1486 (test-equal "tan(-0.5+0.5i)"
1487 (tan (make-rectangular -0.5 0.5))
1488 (make-rectangular -0.4038964553160257 0.5640831412674985))
1489 (test-equal "atan(tan(-0.5+0.5i))"
1490 (atan (tan (make-rectangular -0.5 0.5)))
1491 (make-rectangular -0.5 0.5))
1492 (test-equal "tan(-1.0+1.0i)"
1493 (tan (make-rectangular -1.0 1.0))
1494 (make-rectangular -0.27175258531951174 1.0839233273386948))
1495 (test-equal "atan(tan(-1.0+1.0i))"
1496 (atan (tan (make-rectangular -1.0 1.0)))
1497 (make-rectangular -1.0 1.0))
1498 (test-equal "tan(-1.0-1.0i)"
1499 (tan (make-rectangular -1.0 -1.0))
1500 (make-rectangular -0.27175258531951174 -1.0839233273386948))
1501 (test-equal "atan(tan(-1.0-1.0i))"
1502 (atan (tan (make-rectangular -1.0 -1.0)))
1503 (make-rectangular -1.0 -1.0))
1504 (test-equal "tan(1.0-1.0i)"
1505 (tan (make-rectangular 1.0 -1.0))
1506 (make-rectangular 0.27175258531951174 -1.0839233273386948))
1507 (test-equal "atan(tan(1.0-1.0i))"
1508 (atan (tan (make-rectangular 1.0 -1.0)))
1509 (make-rectangular 1.0 -1.0))
1510 (test-equal "tan(2.0+3.0i)"
1511 (tan (make-rectangular 2.0 3.0))
1512 (make-rectangular -0.0037640256415040815 1.0032386273536098))
1513 (test-equal "atan(tan(2.0+3.0i))"
1514 (atan (tan (make-rectangular 2.0 3.0)))
1515 (make-rectangular -1.1415926535898042 3.0))
1516 (test-equal "tan(-2.0+3.0i)"
1517 (tan (make-rectangular -2.0 3.0))
1518 (make-rectangular 0.0037640256415040815 1.0032386273536098))
1519 (test-equal "atan(tan(-2.0+3.0i))"
1520 (atan (tan (make-rectangular -2.0 3.0)))
1521 (make-rectangular 1.1415926535898042 3.0))
1522 (test-equal "tan(-2.0-3.0i)"
1523 (tan (make-rectangular -2.0 -3.0))
1524 (make-rectangular 0.0037640256415040815 -1.0032386273536098))
1525 (test-equal "atan(tan(-2.0-3.0i))"
1526 (atan (tan (make-rectangular -2.0 -3.0)))
1527 (make-rectangular 1.1415926535898042 -3.0))
1528 (test-equal "tan(2.0-3.0i)"
1529 (tan (make-rectangular 2.0 -3.0))
1530 (make-rectangular -0.0037640256415040815 -1.0032386273536098))
1531 (test-equal "atan(tan(2.0-3.0i))"
1532 (atan (tan (make-rectangular 2.0 -3.0)))
1533 (make-rectangular -1.1415926535898042 -3.0))
1534 ;; Specialization check
1535 (test-equal "tan(atan(2.0-3.0i))"
1536 (tan (atan (make-rectangular 2.0 -3.0)))
1537 (make-rectangular 2.0 -3.0))
1538
1539 )
1540
1541 ;; This is just a handful to determine that we're able to accept these.
1542 ;; Maybe determine better values to test with?
1543 (test-group "bignums"
1544 (test-equal "acos(<negative bignum>)" (acos (- b1)) -nan.0)
1545 ;; These are bogus (maybe the negative ones too!), but I don't want to
1546 ;; "fix" them by copying the output and assume it's alright.
1547 #;(test-equal "acos(<bignum>)" (acos b1) +nan.0)
1548 (test-equal "asin(<negative bignum>)" (asin (- b1)) -nan.0)
1549 #;(test-equal "asin(<bignum>)" (asin b1) +nan.0)
1550 (test-equal "atan(<negative bignum>)" (atan (- b1)) (- (/ pi 2)))
1551 (test-equal "atan(<bignum>)" (atan b1) (/ pi 2)))
1552
1553 ;; This should probably be enough; we're only testing conversion to flonums
1554 ;; and specialization. The actual functionality of cos is checked above.
1555 (test-group "fixnums"
1556 (test-equal "cos(0)" (cos 0) 1.0)
1557 (test-equal "acos(0)" (acos 0) (/ pi 2))
1558 (test-equal "cos(1)" (cos 1) (cos 1.0))
1559 (test-equal "acos(1)" (acos 1) 0.0)
1560 (test-equal "cos(-1)" (cos -1) (cos -1.0))
1561 (test-equal "acos(-1)" (acos -1) pi)
1562 (test-equal "acos(-2)" (acos -2) (make-rectangular pi -1.31695789692482))
1563 (test-equal "acos(2)" (acos 2) 0.0+1.31695789692482i)
1564 (test-equal "asin(1)" (asin 1) (/ pi 2))
1565 (test-equal "asin(-1)" (asin -1) (/ pi -2))
1566 (test-equal "asin(2)" (asin 2) (make-rectangular (/ pi 2) -1.31695789692482))
1567 (test-equal "asin(-2)" (asin -2) (make-rectangular (/ pi -2) 1.31695789692482)))
1568
1569 (test-group "ratnums"
1570 (test-equal "acos(<small number>)" (acos (/ -999999999 2)) -nan.0)
1571 (test-equal "cos(-1/3pi)" (cos (- (/ ratpi 3))) 0.5)
1572 (test-equal "acos(cos(-1/3pi))" (acos (cos (- (/ ratpi 3)))) (/ pi 3))
1573 (test-equal "cos(-1/4pi)" (cos (- (/ ratpi 4))) 0.7071067811865476)
1574 (test-equal "acos(cos(-1/4pi))" (acos (cos (- (/ ratpi 4)))) (/ pi 4))
1575 (test-equal "cos(-1/2pi)" (cos (- (/ ratpi 2))) 0.0)
1576 (test-equal "acos(cos(-1/2pi))" (acos (cos (- (/ ratpi 2)))) (/ pi 2))
1577 (test-equal "cos(-pi)" (cos (- ratpi)) -1.0)
1578 (test-equal "acos(cos(-pi))" (acos (cos (- ratpi))) pi)
1579 (test-equal "cos(0)" (cos 0.0) 1.0)
1580 (test-equal "acos(cos(0))" (acos (cos 0.0)) 0.0)
1581 (test-equal "cos( 1/4pi)" (cos (/ ratpi 4)) 0.7071067811865476)
1582 (test-equal "acos(cos( 1/4pi))" (acos (cos (/ ratpi 4))) (/ pi 4))
1583 (test-equal "cos( 1/3pi)" (cos (/ ratpi 3)) 0.5)
1584 (test-equal "acos(cos( 1/3pi))" (acos (cos (/ ratpi 3))) (/ pi 3))
1585 (test-equal "cos( 1/2pi)" (cos (/ ratpi 2)) 0.0)
1586 (test-equal "acos(cos( 1/2pi))" (acos (cos (/ ratpi 2))) (/ pi 2))
1587 (test-equal "cos( 2/3pi)" (cos (/ (* 2 ratpi) 3)) -0.5)
1588 (test-equal "acos(cos( 2/3pi))" (acos (cos (/ (* 2 ratpi) 3))) (/ (* 2 pi) 3))
1589 (test-equal "cos( 3/4pi)" (cos (* (/ ratpi 4) 3)) -0.7071067811865476)
1590 (test-equal "acos(cos( 3/4pi))" (acos (cos (* (/ ratpi 4) 3))) (* (/ pi 4) 3))
1591 (test-equal "cos( pi)" (cos ratpi) -1.0)
1592 (test-equal "acos(cos( pi))" (acos (cos ratpi)) pi)
1593 (test-equal "cos( 3/2pi)" (cos (+ ratpi (/ ratpi 2))) 0.0)
1594 (test-equal "acos(cos( 3/2pi))" (acos (cos (+ ratpi (/ ratpi 2)))) (/ pi 2))
1595 (test-equal "cos( 4/3pi)" (cos (+ ratpi (/ ratpi 3))) -0.5)
1596 (test-equal "acos(cos( 4/3pi))" (acos (cos (+ ratpi (/ ratpi 3)))) (* 2 (/ pi 3)))
1597 (test-equal "cos( 5/4pi)" (cos (+ ratpi (/ ratpi 4))) -0.7071067811865476)
1598 (test-equal "acos(cos( 5/4pi))" (acos (cos (+ ratpi (/ ratpi 4)))) (* 3 (/ pi 4)))
1599 (test-equal "cos( 2pi)" (cos (* 2 pi)) 1.0)
1600 (test-equal "acos(cos( 2pi))" (acos (cos (* 2 ratpi))) 0)
1601
1602 (test-equal "sin(-1/3pi)" (sin (- (/ ratpi 3))) -0.8660254037844386)
1603 (test-equal "asin(sin(-1/3pi))" (asin (sin (- (/ ratpi 3)))) (- (/ pi 3)))
1604 (test-equal "sin(-1/4pi)" (sin (- (/ ratpi 4))) -0.7071067811865476)
1605 (test-equal "asin(sin(-1/4pi))" (asin (sin (- (/ ratpi 4)))) (- (/ pi 4)))
1606 (test-equal "sin(-1/2pi)" (sin (- (/ ratpi 2))) -1.0)
1607 (test-equal "asin(sin(-1/2pi))" (asin (sin (- (/ ratpi 2)))) (- (/ pi 2)))
1608 (test-equal "sin(-pi)" (sin (- ratpi)) 0.0)
1609 (test-equal "asin(sin(-pi))" (asin (sin (- ratpi))) 0.0)
1610 (test-equal "sin(0)" (sin 0.0) 0.0)
1611 (test-equal "asin(sin(0))" (asin (sin 0.0)) 0.0)
1612 (test-equal "sin( 1/4pi)" (sin (/ ratpi 4)) 0.7071067811865476)
1613 (test-equal "asin(sin( 1/4pi))" (asin (sin (/ ratpi 4))) (/ pi 4))
1614 (test-equal "sin( 1/3pi)" (sin (/ ratpi 3)) 0.8660254037844386)
1615 (test-equal "asin(sin( 1/3pi))" (asin (sin (/ ratpi 3))) (/ pi 3))
1616 (test-equal "sin( 1/2pi)" (sin (/ ratpi 2)) 1.0)
1617 (test-equal "asin(sin( 1/2pi))" (asin (sin (/ ratpi 2))) (/ pi 2))
1618 (test-equal "sin( 2/3pi)" (sin (/ (* 2 ratpi) 3)) 0.8660254037844386)
1619 (test-equal "asin(sin( 2/3pi))" (asin (sin (/ (* 2 ratpi) 3))) (/ pi 3))
1620 (test-equal "sin( 3/4pi)" (sin (* (/ ratpi 4) 3)) 0.7071067811865476)
1621 (test-equal "asin(sin( 3/4pi))" (asin (sin (* (/ ratpi 4) 3))) (/ pi 4))
1622 (test-equal "sin( pi)" (sin ratpi) 0.0)
1623 (test-equal "asin(sin( pi))" (asin (sin ratpi)) 0.0)
1624 (test-equal "sin( 3/2pi)" (sin (+ ratpi (/ ratpi 2))) -1.0)
1625 (test-equal "asin(sin( 3/2pi))" (asin (sin (+ ratpi (/ ratpi 2)))) (- (/ pi 2)))
1626 (test-equal "sin( 4/3pi)" (sin (+ ratpi (/ ratpi 3))) -0.8660254037844386)
1627 (test-equal "asin(sin( 4/3pi))" (asin (sin (+ ratpi (/ ratpi 3)))) (- (/ pi 3)))
1628 (test-equal "sin( 5/4pi)" (sin (+ ratpi (/ ratpi 4))) -0.7071067811865476)
1629 (test-equal "asin(sin( 5/4pi))" (asin (sin (+ ratpi (/ ratpi 4)))) (- (/ pi 4)))
1630 (test-equal "sin( 2pi)" (sin (* 2 ratpi)) 0.0)
1631 (test-equal "asin(sin( 2pi))" (asin (sin (* 2 ratpi))) 0.0)
1632
1633 (test-equal "tan(-1/3pi)" (tan (- (/ ratpi 3))) -1.7320508075688773)
1634 (test-equal "atan(tan(-1/3pi))" (atan (tan (- (/ ratpi 3)))) (- (/ pi 3)))
1635 (test-equal "tan(-1/4pi)" (tan (- (/ ratpi 4))) -1.0)
1636 (test-equal "atan(tan(-1/4pi))" (atan (tan (- (/ ratpi 4)))) (- (/ pi 4)))
1637 ;; NOTE: tan(-(/ pi 2)) should be -inf(?), but isn't. Is that a bug?
1638 (test-equal "tan(-pi)" (tan (- ratpi)) 0.0)
1639 (test-equal "atan(tan(-pi))" (atan (tan (- ratpi))) 0.0)
1640 (test-equal "tan(0)" (tan 0.0) 0.0)
1641 (test-equal "atan(tan(0))" (atan (tan 0.0)) 0.0)
1642 (test-equal "tan( 1/4pi)" (tan (/ ratpi 4)) 1.0)
1643 (test-equal "atan(tan( 1/4pi))" (atan (tan (/ ratpi 4))) (/ pi 4))
1644 (test-equal "tan( 1/3pi)" (tan (/ ratpi 3)) 1.7320508075688773)
1645 (test-equal "atan(tan( 1/3pi))" (atan (tan (/ ratpi 3))) (/ pi 3))
1646 (test-equal "tan( 2/3pi)" (tan (/ (* 2 ratpi) 3)) -1.7320508075688773)
1647 (test-equal "atan(tan( 2/3pi))" (atan (tan (/ (* 2 ratpi) 3))) (- (/ pi 3)))
1648 (test-equal "tan( 3/4pi)" (tan (* (/ ratpi 4) 3)) -1.0)
1649 (test-equal "atan(tan( 3/4pi))" (atan (tan (* (/ ratpi 4) 3))) (- (/ pi 4)))
1650 (test-equal "tan( pi)" (tan ratpi) 0.0)
1651 (test-equal "atan(tan( pi))" (atan (tan ratpi)) 0.0)
1652 (test-equal "tan( 4/3pi)" (tan (+ ratpi (/ ratpi 3))) 1.7320508075688773)
1653 (test-equal "atan(tan( 4/3pi))" (atan (tan (+ ratpi (/ ratpi 3)))) (/ pi 3))
1654 (test-equal "tan( 5/4pi)" (tan (+ ratpi (/ ratpi 4))) 1.0)
1655 (test-equal "atan(tan( 5/4pi))" (atan (tan (+ ratpi (/ ratpi 4)))) (/ pi 4))
1656 (test-equal "tan( 2pi)" (tan (* 2 ratpi)) 0.0)
1657 (test-equal "atan(tan( 2i))" (atan (tan (* 2 ratpi))) 0.0)
1658
1659 (test-equal "atan2(3, tan(pi))" (atan 3 (tan ratpi)) (/ pi 2))
1660 (test-equal "atan2(3, -tan(pi))" (atan 3 (- (tan ratpi))) (/ pi 2))
1661 (test-equal "atan2(-3, tan(pi))" (atan -3 (tan ratpi)) (- (/ pi 2)))
1662 (test-equal "atan2(-3, -tan(pi))" (atan -3 (- (tan ratpi))) (- (/ pi 2))))))
1663
1664(test-end)
1665
1666;(unless (zero? (test-failure-count)) (exit 1))
1667(test-exit)