Commit | Line | Data |
---|---|---|
de142bea | 1 | ;;;; numbers.test --- tests guile's numbers -*- scheme -*- |
96e30d2a | 2 | ;;;; Copyright (C) 2000, 2001 Free Software Foundation, Inc. |
de142bea | 3 | ;;;; |
73be1d9e MV |
4 | ;;;; This library is free software; you can redistribute it and/or |
5 | ;;;; modify it under the terms of the GNU Lesser General Public | |
6 | ;;;; License as published by the Free Software Foundation; either | |
7 | ;;;; version 2.1 of the License, or (at your option) any later version. | |
8 | ;;;; | |
9 | ;;;; This library is distributed in the hope that it will be useful, | |
de142bea | 10 | ;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
73be1d9e MV |
11 | ;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
12 | ;;;; Lesser General Public License for more details. | |
13 | ;;;; | |
14 | ;;;; You should have received a copy of the GNU Lesser General Public | |
15 | ;;;; License along with this library; if not, write to the Free Software | |
16 | ;;;; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
de142bea | 17 | |
cb18f2a8 | 18 | (use-modules (ice-9 documentation)) |
de142bea | 19 | |
de142bea DH |
20 | ;;; |
21 | ;;; miscellaneous | |
22 | ;;; | |
23 | ||
1b3a7932 DH |
24 | (define exception:numerical-overflow |
25 | (cons 'numerical-overflow "^Numerical overflow")) | |
26 | ||
cb18f2a8 | 27 | (define (documented? object) |
5c96bc39 | 28 | (not (not (object-documentation object)))) |
de142bea | 29 | |
8b7838b5 RB |
30 | (define fixnum-bit |
31 | (inexact->exact (+ (/ (log (+ most-positive-fixnum 1)) (log 2)) 1))) | |
32 | ||
21e39e8f DH |
33 | (define fixnum-min most-negative-fixnum) |
34 | (define fixnum-max most-positive-fixnum) | |
de142bea | 35 | |
de142bea DH |
36 | ;;; |
37 | ;;; exact? | |
38 | ;;; | |
39 | ||
40 | (with-test-prefix "exact?" | |
41 | ||
de142bea | 42 | (pass-if "documented?" |
cb18f2a8 | 43 | (documented? exact?)) |
de142bea | 44 | |
21e39e8f | 45 | (with-test-prefix "integers" |
de142bea | 46 | |
21e39e8f DH |
47 | (pass-if "0" |
48 | (exact? 0)) | |
de142bea | 49 | |
21e39e8f DH |
50 | (pass-if "fixnum-max" |
51 | (exact? fixnum-max)) | |
de142bea | 52 | |
21e39e8f DH |
53 | (pass-if "fixnum-max + 1" |
54 | (exact? (+ fixnum-max 1))) | |
de142bea | 55 | |
21e39e8f DH |
56 | (pass-if "fixnum-min" |
57 | (exact? fixnum-min)) | |
de142bea | 58 | |
21e39e8f DH |
59 | (pass-if "fixnum-min - 1" |
60 | (exact? (- fixnum-min 1)))) | |
61 | ||
62 | (with-test-prefix "reals" | |
63 | ||
64 | ;; (FIXME: need better examples.) | |
65 | ||
66 | (pass-if "sqrt (fixnum-max^2 - 1)" | |
67 | (eq? #f (exact? (sqrt (- (expt fixnum-max 2) 1))))) | |
68 | ||
69 | (pass-if "sqrt ((fixnum-max+1)^2 - 1)" | |
70 | (eq? #f (exact? (sqrt (- (expt (+ fixnum-max 1) 2) 1))))))) | |
de142bea DH |
71 | |
72 | ;;; | |
73 | ;;; odd? | |
74 | ;;; | |
75 | ||
7c24e528 RB |
76 | (with-test-prefix "odd?" |
77 | (pass-if (documented? odd?)) | |
78 | (pass-if (odd? 1)) | |
79 | (pass-if (odd? -1)) | |
80 | (expect-fail (odd? 0)) | |
81 | (expect-fail (odd? 2)) | |
82 | (expect-fail (odd? -2)) | |
83 | (pass-if (odd? (+ (* 2 fixnum-max) 1))) | |
84 | (expect-fail (odd? (* 2 fixnum-max))) | |
85 | (pass-if (odd? (- (* 2 fixnum-min) 1))) | |
86 | (expect-fail (odd? (* 2 fixnum-min)))) | |
de142bea DH |
87 | |
88 | ;;; | |
89 | ;;; even? | |
90 | ;;; | |
91 | ||
7c24e528 RB |
92 | (with-test-prefix "even?" |
93 | (pass-if (documented? even?)) | |
94 | (pass-if (even? 2)) | |
95 | (pass-if (even? -2)) | |
96 | (pass-if (even? 0)) | |
97 | (expect-fail (even? 1)) | |
98 | (expect-fail (even? -1)) | |
99 | (expect-fail (even? (+ (* 2 fixnum-max) 1))) | |
100 | (pass-if (even? (* 2 fixnum-max))) | |
101 | (expect-fail (even? (- (* 2 fixnum-min) 1))) | |
102 | (pass-if (even? (* 2 fixnum-min)))) | |
de142bea DH |
103 | |
104 | ;;; | |
7c24e528 RB |
105 | ;;; inf? and inf |
106 | ;;; | |
107 | ||
108 | (with-test-prefix "inf?" | |
109 | (pass-if (documented? inf?)) | |
110 | (pass-if (inf? (inf))) | |
111 | ;; FIXME: what are the expected behaviors? | |
112 | ;; (pass-if (inf? (/ 1.0 0.0)) | |
113 | ;; (pass-if (inf? (/ 1 0.0)) | |
114 | (expect-fail (inf? 0)) | |
115 | (expect-fail (inf? 42.0)) | |
116 | (expect-fail (inf? (+ fixnum-max 1))) | |
117 | (expect-fail (inf? (- fixnum-min 1)))) | |
118 | ||
119 | ;;; | |
120 | ;;; nan? and nan | |
de142bea DH |
121 | ;;; |
122 | ||
7c24e528 RB |
123 | (with-test-prefix "nan?" |
124 | (pass-if (documented? nan?)) | |
125 | (pass-if (nan? (nan))) | |
126 | ;; FIXME: other ways we should be able to generate NaN? | |
127 | (expect-fail (nan? 0)) | |
128 | (expect-fail (nan? 42.0)) | |
129 | (expect-fail (nan? (+ fixnum-max 1))) | |
130 | (expect-fail (nan? (- fixnum-min 1)))) | |
de142bea | 131 | |
7c24e528 RB |
132 | ;;; |
133 | ;;; abs | |
134 | ;;; | |
135 | ||
136 | (with-test-prefix "abs" | |
137 | (pass-if (documented? abs)) | |
138 | (pass-if (zero? (abs 0))) | |
139 | (pass-if (= 1 (abs 1))) | |
140 | (pass-if (= 1 (abs -1))) | |
141 | (pass-if (= (+ fixnum-max 1) (abs (+ fixnum-max 1)))) | |
142 | (pass-if (= (+ (- fixnum-min) 1) (abs (- fixnum-min 1)))) | |
143 | (pass-if (positive? (abs 1.0))) | |
144 | (pass-if (positive? (abs -1.0)))) | |
145 | ||
de142bea DH |
146 | ;;; |
147 | ;;; quotient | |
148 | ;;; | |
149 | ||
150 | (with-test-prefix "quotient" | |
151 | ||
de142bea | 152 | (expect-fail "documented?" |
cb18f2a8 | 153 | (documented? quotient)) |
de142bea | 154 | |
de142bea DH |
155 | (with-test-prefix "0 / n" |
156 | ||
157 | (pass-if "n = 1" | |
158 | (eqv? 0 (quotient 0 1))) | |
159 | ||
160 | (pass-if "n = -1" | |
161 | (eqv? 0 (quotient 0 -1))) | |
162 | ||
21e39e8f DH |
163 | (pass-if "n = 2" |
164 | (eqv? 0 (quotient 0 2))) | |
165 | ||
166 | (pass-if "n = fixnum-max" | |
167 | (eqv? 0 (quotient 0 fixnum-max))) | |
168 | ||
169 | (pass-if "n = fixnum-max + 1" | |
170 | (eqv? 0 (quotient 0 (+ fixnum-max 1)))) | |
171 | ||
172 | (pass-if "n = fixnum-min" | |
173 | (eqv? 0 (quotient 0 fixnum-min))) | |
174 | ||
175 | (pass-if "n = fixnum-min - 1" | |
176 | (eqv? 0 (quotient 0 (- fixnum-min 1))))) | |
de142bea | 177 | |
21e39e8f | 178 | (with-test-prefix "1 / n" |
de142bea DH |
179 | |
180 | (pass-if "n = 1" | |
181 | (eqv? 1 (quotient 1 1))) | |
182 | ||
183 | (pass-if "n = -1" | |
21e39e8f DH |
184 | (eqv? -1 (quotient 1 -1))) |
185 | ||
186 | (pass-if "n = 2" | |
187 | (eqv? 0 (quotient 1 2))) | |
de142bea | 188 | |
21e39e8f DH |
189 | (pass-if "n = fixnum-max" |
190 | (eqv? 0 (quotient 1 fixnum-max))) | |
de142bea | 191 | |
21e39e8f DH |
192 | (pass-if "n = fixnum-max + 1" |
193 | (eqv? 0 (quotient 1 (+ fixnum-max 1)))) | |
de142bea | 194 | |
21e39e8f DH |
195 | (pass-if "n = fixnum-min" |
196 | (eqv? 0 (quotient 1 fixnum-min))) | |
197 | ||
198 | (pass-if "n = fixnum-min - 1" | |
199 | (eqv? 0 (quotient 1 (- fixnum-min 1))))) | |
200 | ||
201 | (with-test-prefix "-1 / n" | |
de142bea DH |
202 | |
203 | (pass-if "n = 1" | |
21e39e8f | 204 | (eqv? -1 (quotient -1 1))) |
de142bea DH |
205 | |
206 | (pass-if "n = -1" | |
207 | (eqv? 1 (quotient -1 -1))) | |
208 | ||
21e39e8f DH |
209 | (pass-if "n = 2" |
210 | (eqv? 0 (quotient -1 2))) | |
211 | ||
212 | (pass-if "n = fixnum-max" | |
213 | (eqv? 0 (quotient -1 fixnum-max))) | |
214 | ||
215 | (pass-if "n = fixnum-max + 1" | |
216 | (eqv? 0 (quotient -1 (+ fixnum-max 1)))) | |
217 | ||
218 | (pass-if "n = fixnum-min" | |
219 | (eqv? 0 (quotient -1 fixnum-min))) | |
220 | ||
221 | (pass-if "n = fixnum-min - 1" | |
222 | (eqv? 0 (quotient -1 (- fixnum-min 1))))) | |
223 | ||
224 | (with-test-prefix "fixnum-max / n" | |
225 | ||
226 | (pass-if "n = 1" | |
227 | (eqv? fixnum-max (quotient fixnum-max 1))) | |
228 | ||
229 | (pass-if "n = -1" | |
230 | (eqv? (- fixnum-max) (quotient fixnum-max -1))) | |
231 | ||
232 | (pass-if "n = 2" | |
233 | (eqv? fixnum-max (+ (* (quotient fixnum-max 2) 2) 1))) | |
234 | ||
235 | (pass-if "n = fixnum-max" | |
236 | (eqv? 1 (quotient fixnum-max fixnum-max))) | |
237 | ||
238 | (pass-if "n = fixnum-max + 1" | |
239 | (eqv? 0 (quotient fixnum-max (+ fixnum-max 1)))) | |
240 | ||
241 | (pass-if "n = fixnum-min" | |
242 | (eqv? 0 (quotient fixnum-max fixnum-min))) | |
243 | ||
244 | (pass-if "n = fixnum-min - 1" | |
245 | (eqv? 0 (quotient fixnum-max (- fixnum-min 1))))) | |
246 | ||
247 | (with-test-prefix "(fixnum-max + 1) / n" | |
248 | ||
249 | (pass-if "n = 1" | |
250 | (eqv? (+ fixnum-max 1) (quotient (+ fixnum-max 1) 1))) | |
251 | ||
252 | (pass-if "n = -1" | |
253 | (eqv? (- (+ fixnum-max 1)) (quotient (+ fixnum-max 1) -1))) | |
254 | ||
255 | (pass-if "n = 2" | |
256 | (eqv? (+ fixnum-max 1) (* (quotient (+ fixnum-max 1) 2) 2))) | |
257 | ||
258 | (pass-if "n = fixnum-max" | |
259 | (eqv? 1 (quotient (+ fixnum-max 1) fixnum-max))) | |
260 | ||
261 | (pass-if "n = fixnum-max + 1" | |
262 | (eqv? 1 (quotient (+ fixnum-max 1) (+ fixnum-max 1)))) | |
263 | ||
264 | (pass-if "n = fixnum-min" | |
265 | (eqv? -1 (quotient (+ fixnum-max 1) fixnum-min))) | |
266 | ||
267 | (pass-if "n = fixnum-min - 1" | |
268 | (eqv? 0 (quotient (+ fixnum-max 1) (- fixnum-min 1))))) | |
269 | ||
270 | (with-test-prefix "fixnum-min / n" | |
271 | ||
272 | (pass-if "n = 1" | |
273 | (eqv? fixnum-min (quotient fixnum-min 1))) | |
274 | ||
275 | (pass-if "n = -1" | |
276 | (eqv? (- fixnum-min) (quotient fixnum-min -1))) | |
277 | ||
278 | (pass-if "n = 2" | |
279 | (eqv? fixnum-min (* (quotient fixnum-min 2) 2))) | |
280 | ||
281 | (pass-if "n = fixnum-max" | |
282 | (eqv? -1 (quotient fixnum-min fixnum-max))) | |
283 | ||
284 | (pass-if "n = fixnum-max + 1" | |
285 | (eqv? -1 (quotient fixnum-min (+ fixnum-max 1)))) | |
286 | ||
287 | (pass-if "n = fixnum-min" | |
288 | (eqv? 1 (quotient fixnum-min fixnum-min))) | |
289 | ||
290 | (pass-if "n = fixnum-min - 1" | |
291 | (eqv? 0 (quotient fixnum-min (- fixnum-min 1))))) | |
292 | ||
293 | (with-test-prefix "(fixnum-min - 1) / n" | |
294 | ||
295 | (pass-if "n = 1" | |
296 | (eqv? (- fixnum-min 1) (quotient (- fixnum-min 1) 1))) | |
297 | ||
298 | (pass-if "n = -1" | |
299 | (eqv? (- (- fixnum-min 1)) (quotient (- fixnum-min 1) -1))) | |
300 | ||
301 | (pass-if "n = 2" | |
302 | (eqv? fixnum-min (* (quotient (- fixnum-min 1) 2) 2))) | |
303 | ||
304 | (pass-if "n = fixnum-max" | |
305 | (eqv? -1 (quotient (- fixnum-min 1) fixnum-max))) | |
306 | ||
307 | (pass-if "n = fixnum-max + 1" | |
308 | (eqv? -1 (quotient (- fixnum-min 1) (+ fixnum-max 1)))) | |
309 | ||
310 | (pass-if "n = fixnum-min" | |
311 | (eqv? 1 (quotient (- fixnum-min 1) fixnum-min))) | |
312 | ||
313 | (pass-if "n = fixnum-min - 1" | |
314 | (eqv? 1 (quotient (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
315 | |
316 | ;; Positive dividend and divisor | |
317 | ||
318 | (pass-if "35 / 7" | |
319 | (eqv? 5 (quotient 35 7))) | |
320 | ||
321 | ;; Negative dividend, positive divisor | |
322 | ||
323 | (pass-if "-35 / 7" | |
324 | (eqv? -5 (quotient -35 7))) | |
325 | ||
326 | ;; Positive dividend, negative divisor | |
327 | ||
328 | (pass-if "35 / -7" | |
329 | (eqv? -5 (quotient 35 -7))) | |
330 | ||
331 | ;; Negative dividend and divisor | |
332 | ||
333 | (pass-if "-35 / -7" | |
334 | (eqv? 5 (quotient -35 -7))) | |
335 | ||
336 | ;; Are numerical overflows detected correctly? | |
337 | ||
80074d77 DH |
338 | (with-test-prefix "division by zero" |
339 | ||
340 | (pass-if-exception "(quotient 1 0)" | |
341 | exception:numerical-overflow | |
342 | (quotient 1 0)) | |
343 | ||
344 | (pass-if-exception "(quotient bignum 0)" | |
345 | exception:numerical-overflow | |
346 | (quotient (+ fixnum-max 1) 0))) | |
347 | ||
de142bea DH |
348 | ;; Are wrong type arguments detected correctly? |
349 | ||
350 | ) | |
351 | ||
352 | ;;; | |
353 | ;;; remainder | |
354 | ;;; | |
355 | ||
356 | (with-test-prefix "remainder" | |
357 | ||
de142bea | 358 | (expect-fail "documented?" |
cb18f2a8 | 359 | (documented? remainder)) |
de142bea | 360 | |
de142bea DH |
361 | (with-test-prefix "0 / n" |
362 | ||
363 | (pass-if "n = 1" | |
364 | (eqv? 0 (remainder 0 1))) | |
365 | ||
366 | (pass-if "n = -1" | |
367 | (eqv? 0 (remainder 0 -1))) | |
368 | ||
21e39e8f DH |
369 | (pass-if "n = fixnum-max" |
370 | (eqv? 0 (remainder 0 fixnum-max))) | |
371 | ||
372 | (pass-if "n = fixnum-max + 1" | |
373 | (eqv? 0 (remainder 0 (+ fixnum-max 1)))) | |
374 | ||
375 | (pass-if "n = fixnum-min" | |
376 | (eqv? 0 (remainder 0 fixnum-min))) | |
de142bea | 377 | |
21e39e8f DH |
378 | (pass-if "n = fixnum-min - 1" |
379 | (eqv? 0 (remainder 0 (- fixnum-min 1))))) | |
de142bea | 380 | |
21e39e8f | 381 | (with-test-prefix "1 / n" |
de142bea DH |
382 | |
383 | (pass-if "n = 1" | |
384 | (eqv? 0 (remainder 1 1))) | |
385 | ||
386 | (pass-if "n = -1" | |
21e39e8f DH |
387 | (eqv? 0 (remainder 1 -1))) |
388 | ||
389 | (pass-if "n = fixnum-max" | |
390 | (eqv? 1 (remainder 1 fixnum-max))) | |
de142bea | 391 | |
21e39e8f DH |
392 | (pass-if "n = fixnum-max + 1" |
393 | (eqv? 1 (remainder 1 (+ fixnum-max 1)))) | |
de142bea | 394 | |
21e39e8f DH |
395 | (pass-if "n = fixnum-min" |
396 | (eqv? 1 (remainder 1 fixnum-min))) | |
de142bea | 397 | |
21e39e8f DH |
398 | (pass-if "n = fixnum-min - 1" |
399 | (eqv? 1 (remainder 1 (- fixnum-min 1))))) | |
400 | ||
401 | (with-test-prefix "-1 / n" | |
de142bea DH |
402 | |
403 | (pass-if "n = 1" | |
21e39e8f | 404 | (eqv? 0 (remainder -1 1))) |
de142bea DH |
405 | |
406 | (pass-if "n = -1" | |
407 | (eqv? 0 (remainder -1 -1))) | |
408 | ||
21e39e8f DH |
409 | (pass-if "n = fixnum-max" |
410 | (eqv? -1 (remainder -1 fixnum-max))) | |
411 | ||
412 | (pass-if "n = fixnum-max + 1" | |
413 | (eqv? -1 (remainder -1 (+ fixnum-max 1)))) | |
414 | ||
415 | (pass-if "n = fixnum-min" | |
416 | (eqv? -1 (remainder -1 fixnum-min))) | |
417 | ||
418 | (pass-if "n = fixnum-min - 1" | |
419 | (eqv? -1 (remainder -1 (- fixnum-min 1))))) | |
420 | ||
421 | (with-test-prefix "fixnum-max / n" | |
422 | ||
423 | (pass-if "n = 1" | |
424 | (eqv? 0 (remainder fixnum-max 1))) | |
425 | ||
426 | (pass-if "n = -1" | |
427 | (eqv? 0 (remainder fixnum-max -1))) | |
428 | ||
429 | (pass-if "n = fixnum-max" | |
430 | (eqv? 0 (remainder fixnum-max fixnum-max))) | |
431 | ||
432 | (pass-if "n = fixnum-max + 1" | |
433 | (eqv? fixnum-max (remainder fixnum-max (+ fixnum-max 1)))) | |
434 | ||
435 | (pass-if "n = fixnum-min" | |
436 | (eqv? fixnum-max (remainder fixnum-max fixnum-min))) | |
437 | ||
438 | (pass-if "n = fixnum-min - 1" | |
439 | (eqv? fixnum-max (remainder fixnum-max (- fixnum-min 1))))) | |
440 | ||
441 | (with-test-prefix "(fixnum-max + 1) / n" | |
442 | ||
443 | (pass-if "n = 1" | |
444 | (eqv? 0 (remainder (+ fixnum-max 1) 1))) | |
445 | ||
446 | (pass-if "n = -1" | |
447 | (eqv? 0 (remainder (+ fixnum-max 1) -1))) | |
448 | ||
449 | (pass-if "n = fixnum-max" | |
450 | (eqv? 1 (remainder (+ fixnum-max 1) fixnum-max))) | |
451 | ||
452 | (pass-if "n = fixnum-max + 1" | |
453 | (eqv? 0 (remainder (+ fixnum-max 1) (+ fixnum-max 1)))) | |
454 | ||
455 | (pass-if "n = fixnum-min" | |
456 | (eqv? 0 (remainder (+ fixnum-max 1) fixnum-min))) | |
457 | ||
458 | (pass-if "n = fixnum-min - 1" | |
459 | (eqv? (+ fixnum-max 1) (remainder (+ fixnum-max 1) (- fixnum-min 1))))) | |
460 | ||
461 | (with-test-prefix "fixnum-min / n" | |
462 | ||
463 | (pass-if "n = 1" | |
464 | (eqv? 0 (remainder fixnum-min 1))) | |
465 | ||
466 | (pass-if "n = -1" | |
467 | (eqv? 0 (remainder fixnum-min -1))) | |
468 | ||
469 | (pass-if "n = fixnum-max" | |
470 | (eqv? -1 (remainder fixnum-min fixnum-max))) | |
471 | ||
472 | (pass-if "n = fixnum-max + 1" | |
473 | (eqv? 0 (remainder fixnum-min (+ fixnum-max 1)))) | |
474 | ||
475 | (pass-if "n = fixnum-min" | |
476 | (eqv? 0 (remainder fixnum-min fixnum-min))) | |
477 | ||
478 | (pass-if "n = fixnum-min - 1" | |
479 | (eqv? fixnum-min (remainder fixnum-min (- fixnum-min 1))))) | |
480 | ||
481 | (with-test-prefix "(fixnum-min - 1) / n" | |
482 | ||
483 | (pass-if "n = 1" | |
484 | (eqv? 0 (remainder (- fixnum-min 1) 1))) | |
485 | ||
486 | (pass-if "n = -1" | |
487 | (eqv? 0 (remainder (- fixnum-min 1) -1))) | |
488 | ||
489 | (pass-if "n = fixnum-max" | |
490 | (eqv? -2 (remainder (- fixnum-min 1) fixnum-max))) | |
491 | ||
492 | (pass-if "n = fixnum-max + 1" | |
493 | (eqv? -1 (remainder (- fixnum-min 1) (+ fixnum-max 1)))) | |
494 | ||
495 | (pass-if "n = fixnum-min" | |
496 | (eqv? -1 (remainder (- fixnum-min 1) fixnum-min))) | |
497 | ||
498 | (pass-if "n = fixnum-min - 1" | |
499 | (eqv? 0 (remainder (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
500 | |
501 | ;; Positive dividend and divisor | |
502 | ||
503 | (pass-if "35 / 7" | |
504 | (eqv? 0 (remainder 35 7))) | |
505 | ||
506 | ;; Negative dividend, positive divisor | |
507 | ||
508 | (pass-if "-35 / 7" | |
509 | (eqv? 0 (remainder -35 7))) | |
510 | ||
511 | ;; Positive dividend, negative divisor | |
512 | ||
513 | (pass-if "35 / -7" | |
514 | (eqv? 0 (remainder 35 -7))) | |
515 | ||
516 | ;; Negative dividend and divisor | |
517 | ||
518 | (pass-if "-35 / -7" | |
519 | (eqv? 0 (remainder -35 -7))) | |
520 | ||
521 | ;; Are numerical overflows detected correctly? | |
522 | ||
80074d77 DH |
523 | (with-test-prefix "division by zero" |
524 | ||
525 | (pass-if-exception "(remainder 1 0)" | |
526 | exception:numerical-overflow | |
527 | (remainder 1 0)) | |
528 | ||
529 | (pass-if-exception "(remainder bignum 0)" | |
530 | exception:numerical-overflow | |
531 | (remainder (+ fixnum-max 1) 0))) | |
532 | ||
de142bea DH |
533 | ;; Are wrong type arguments detected correctly? |
534 | ||
535 | ) | |
536 | ||
537 | ;;; | |
538 | ;;; modulo | |
539 | ;;; | |
540 | ||
541 | (with-test-prefix "modulo" | |
542 | ||
de142bea | 543 | (expect-fail "documented?" |
cb18f2a8 | 544 | (documented? modulo)) |
de142bea | 545 | |
de142bea DH |
546 | (with-test-prefix "0 % n" |
547 | ||
548 | (pass-if "n = 1" | |
549 | (eqv? 0 (modulo 0 1))) | |
550 | ||
551 | (pass-if "n = -1" | |
552 | (eqv? 0 (modulo 0 -1))) | |
553 | ||
21e39e8f DH |
554 | (pass-if "n = fixnum-max" |
555 | (eqv? 0 (modulo 0 fixnum-max))) | |
556 | ||
557 | (pass-if "n = fixnum-max + 1" | |
558 | (eqv? 0 (modulo 0 (+ fixnum-max 1)))) | |
de142bea | 559 | |
21e39e8f DH |
560 | (pass-if "n = fixnum-min" |
561 | (eqv? 0 (modulo 0 fixnum-min))) | |
de142bea | 562 | |
21e39e8f DH |
563 | (pass-if "n = fixnum-min - 1" |
564 | (eqv? 0 (modulo 0 (- fixnum-min 1))))) | |
565 | ||
566 | (with-test-prefix "1 % n" | |
de142bea DH |
567 | |
568 | (pass-if "n = 1" | |
569 | (eqv? 0 (modulo 1 1))) | |
570 | ||
571 | (pass-if "n = -1" | |
21e39e8f | 572 | (eqv? 0 (modulo 1 -1))) |
de142bea | 573 | |
21e39e8f DH |
574 | (pass-if "n = fixnum-max" |
575 | (eqv? 1 (modulo 1 fixnum-max))) | |
de142bea | 576 | |
21e39e8f DH |
577 | (pass-if "n = fixnum-max + 1" |
578 | (eqv? 1 (modulo 1 (+ fixnum-max 1)))) | |
de142bea | 579 | |
21e39e8f DH |
580 | (pass-if "n = fixnum-min" |
581 | (eqv? (+ fixnum-min 1) (modulo 1 fixnum-min))) | |
582 | ||
583 | (pass-if "n = fixnum-min - 1" | |
584 | (eqv? fixnum-min (modulo 1 (- fixnum-min 1))))) | |
585 | ||
586 | (with-test-prefix "-1 % n" | |
de142bea DH |
587 | |
588 | (pass-if "n = 1" | |
21e39e8f | 589 | (eqv? 0 (modulo -1 1))) |
de142bea DH |
590 | |
591 | (pass-if "n = -1" | |
592 | (eqv? 0 (modulo -1 -1))) | |
593 | ||
21e39e8f DH |
594 | (pass-if "n = fixnum-max" |
595 | (eqv? (- fixnum-max 1) (modulo -1 fixnum-max))) | |
596 | ||
597 | (pass-if "n = fixnum-max + 1" | |
598 | (eqv? fixnum-max (modulo -1 (+ fixnum-max 1)))) | |
599 | ||
600 | (pass-if "n = fixnum-min" | |
601 | (eqv? -1 (modulo -1 fixnum-min))) | |
602 | ||
603 | (pass-if "n = fixnum-min - 1" | |
604 | (eqv? -1 (modulo -1 (- fixnum-min 1))))) | |
605 | ||
606 | (with-test-prefix "fixnum-max % n" | |
607 | ||
608 | (pass-if "n = 1" | |
609 | (eqv? 0 (modulo fixnum-max 1))) | |
610 | ||
611 | (pass-if "n = -1" | |
612 | (eqv? 0 (modulo fixnum-max -1))) | |
613 | ||
614 | (pass-if "n = fixnum-max" | |
615 | (eqv? 0 (modulo fixnum-max fixnum-max))) | |
616 | ||
617 | (pass-if "n = fixnum-max + 1" | |
618 | (eqv? fixnum-max (modulo fixnum-max (+ fixnum-max 1)))) | |
619 | ||
620 | (pass-if "n = fixnum-min" | |
621 | (eqv? -1 (modulo fixnum-max fixnum-min))) | |
622 | ||
623 | (pass-if "n = fixnum-min - 1" | |
624 | (eqv? -2 (modulo fixnum-max (- fixnum-min 1))))) | |
625 | ||
626 | (with-test-prefix "(fixnum-max + 1) % n" | |
627 | ||
628 | (pass-if "n = 1" | |
629 | (eqv? 0 (modulo (+ fixnum-max 1) 1))) | |
630 | ||
631 | (pass-if "n = -1" | |
632 | (eqv? 0 (modulo (+ fixnum-max 1) -1))) | |
633 | ||
634 | (pass-if "n = fixnum-max" | |
635 | (eqv? 1 (modulo (+ fixnum-max 1) fixnum-max))) | |
636 | ||
637 | (pass-if "n = fixnum-max + 1" | |
638 | (eqv? 0 (modulo (+ fixnum-max 1) (+ fixnum-max 1)))) | |
639 | ||
640 | (pass-if "n = fixnum-min" | |
641 | (eqv? 0 (modulo (+ fixnum-max 1) fixnum-min))) | |
642 | ||
643 | (pass-if "n = fixnum-min - 1" | |
644 | (eqv? -1 (modulo (+ fixnum-max 1) (- fixnum-min 1))))) | |
645 | ||
646 | (with-test-prefix "fixnum-min % n" | |
647 | ||
648 | (pass-if "n = 1" | |
649 | (eqv? 0 (modulo fixnum-min 1))) | |
650 | ||
651 | (pass-if "n = -1" | |
652 | (eqv? 0 (modulo fixnum-min -1))) | |
653 | ||
654 | (pass-if "n = fixnum-max" | |
655 | (eqv? (- fixnum-max 1) (modulo fixnum-min fixnum-max))) | |
656 | ||
657 | (pass-if "n = fixnum-max + 1" | |
658 | (eqv? 0 (modulo fixnum-min (+ fixnum-max 1)))) | |
659 | ||
660 | (pass-if "n = fixnum-min" | |
661 | (eqv? 0 (modulo fixnum-min fixnum-min))) | |
662 | ||
663 | (pass-if "n = fixnum-min - 1" | |
664 | (eqv? fixnum-min (modulo fixnum-min (- fixnum-min 1))))) | |
665 | ||
666 | (with-test-prefix "(fixnum-min - 1) % n" | |
667 | ||
668 | (pass-if "n = 1" | |
669 | (eqv? 0 (modulo (- fixnum-min 1) 1))) | |
670 | ||
671 | (pass-if "n = -1" | |
672 | (eqv? 0 (modulo (- fixnum-min 1) -1))) | |
673 | ||
674 | (pass-if "n = fixnum-max" | |
675 | (eqv? (- fixnum-max 2) (modulo (- fixnum-min 1) fixnum-max))) | |
676 | ||
677 | (pass-if "n = fixnum-max + 1" | |
678 | (eqv? fixnum-max (modulo (- fixnum-min 1) (+ fixnum-max 1)))) | |
679 | ||
680 | (pass-if "n = fixnum-min" | |
681 | (eqv? -1 (modulo (- fixnum-min 1) fixnum-min))) | |
682 | ||
683 | (pass-if "n = fixnum-min - 1" | |
684 | (eqv? 0 (modulo (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
685 | |
686 | ;; Positive dividend and divisor | |
687 | ||
688 | (pass-if "13 % 4" | |
689 | (eqv? 1 (modulo 13 4))) | |
690 | ||
691 | (pass-if "2177452800 % 86400" | |
692 | (eqv? 0 (modulo 2177452800 86400))) | |
693 | ||
694 | ;; Negative dividend, positive divisor | |
695 | ||
696 | (pass-if "-13 % 4" | |
697 | (eqv? 3 (modulo -13 4))) | |
698 | ||
699 | (pass-if "-2177452800 % 86400" | |
700 | (eqv? 0 (modulo -2177452800 86400))) | |
701 | ||
702 | ;; Positive dividend, negative divisor | |
703 | ||
704 | (pass-if "13 % -4" | |
705 | (eqv? -3 (modulo 13 -4))) | |
706 | ||
707 | (pass-if "2177452800 % -86400" | |
708 | (eqv? 0 (modulo 2177452800 -86400))) | |
709 | ||
710 | ;; Negative dividend and divisor | |
711 | ||
712 | (pass-if "-13 % -4" | |
713 | (eqv? -1 (modulo -13 -4))) | |
714 | ||
715 | (pass-if "-2177452800 % -86400" | |
716 | (eqv? 0 (modulo -2177452800 -86400))) | |
717 | ||
718 | ;; Are numerical overflows detected correctly? | |
719 | ||
80074d77 DH |
720 | (with-test-prefix "division by zero" |
721 | ||
722 | (pass-if-exception "(modulo 1 0)" | |
723 | exception:numerical-overflow | |
724 | (modulo 1 0)) | |
725 | ||
726 | (pass-if-exception "(modulo bignum 0)" | |
727 | exception:numerical-overflow | |
728 | (modulo (+ fixnum-max 1) 0))) | |
729 | ||
de142bea DH |
730 | ;; Are wrong type arguments detected correctly? |
731 | ||
732 | ) | |
733 | ||
734 | ;;; | |
735 | ;;; gcd | |
736 | ;;; | |
737 | ||
738 | (with-test-prefix "gcd" | |
739 | ||
de142bea | 740 | (expect-fail "documented?" |
cb18f2a8 | 741 | (documented? gcd)) |
de142bea | 742 | |
de142bea DH |
743 | (with-test-prefix "(0 n)" |
744 | ||
21e39e8f DH |
745 | (pass-if "n = 0" |
746 | (eqv? 0 (gcd 0 0))) | |
747 | ||
de142bea DH |
748 | (pass-if "n = 1" |
749 | (eqv? 1 (gcd 0 1))) | |
750 | ||
751 | (pass-if "n = -1" | |
752 | (eqv? 1 (gcd 0 -1))) | |
753 | ||
21e39e8f DH |
754 | (pass-if "n = fixnum-max" |
755 | (eqv? fixnum-max (gcd 0 fixnum-max))) | |
de142bea | 756 | |
21e39e8f DH |
757 | (pass-if "n = fixnum-max + 1" |
758 | (eqv? (+ fixnum-max 1) (gcd 0 (+ fixnum-max 1)))) | |
de142bea | 759 | |
21e39e8f DH |
760 | (pass-if "n = fixnum-min" |
761 | (eqv? (- fixnum-min) (gcd 0 fixnum-min))) | |
de142bea | 762 | |
21e39e8f DH |
763 | (pass-if "n = fixnum-min - 1" |
764 | (eqv? (- (- fixnum-min 1)) (gcd 0 (- fixnum-min 1))))) | |
765 | ||
766 | (with-test-prefix "(1 n)" | |
767 | ||
768 | (pass-if "n = 0" | |
de142bea DH |
769 | (eqv? 1 (gcd 1 0))) |
770 | ||
21e39e8f DH |
771 | (pass-if "n = 1" |
772 | (eqv? 1 (gcd 1 1))) | |
773 | ||
de142bea | 774 | (pass-if "n = -1" |
21e39e8f DH |
775 | (eqv? 1 (gcd 1 -1))) |
776 | ||
777 | (pass-if "n = fixnum-max" | |
778 | (eqv? 1 (gcd 1 fixnum-max))) | |
779 | ||
780 | (pass-if "n = fixnum-max + 1" | |
781 | (eqv? 1 (gcd 1 (+ fixnum-max 1)))) | |
782 | ||
783 | (pass-if "n = fixnum-min" | |
784 | (eqv? 1 (gcd 1 fixnum-min))) | |
785 | ||
786 | (pass-if "n = fixnum-min - 1" | |
787 | (eqv? 1 (gcd 1 (- fixnum-min 1))))) | |
788 | ||
789 | (with-test-prefix "(-1 n)" | |
790 | ||
791 | (pass-if "n = 0" | |
de142bea DH |
792 | (eqv? 1 (gcd -1 0))) |
793 | ||
21e39e8f DH |
794 | (pass-if "n = 1" |
795 | (eqv? 1 (gcd -1 1))) | |
de142bea | 796 | |
21e39e8f DH |
797 | (pass-if "n = -1" |
798 | (eqv? 1 (gcd -1 -1))) | |
de142bea | 799 | |
21e39e8f DH |
800 | (pass-if "n = fixnum-max" |
801 | (eqv? 1 (gcd -1 fixnum-max))) | |
802 | ||
803 | (pass-if "n = fixnum-max + 1" | |
804 | (eqv? 1 (gcd -1 (+ fixnum-max 1)))) | |
805 | ||
806 | (pass-if "n = fixnum-min" | |
807 | (eqv? 1 (gcd -1 fixnum-min))) | |
808 | ||
809 | (pass-if "n = fixnum-min - 1" | |
810 | (eqv? 1 (gcd -1 (- fixnum-min 1))))) | |
811 | ||
812 | (with-test-prefix "(fixnum-max n)" | |
813 | ||
814 | (pass-if "n = 0" | |
815 | (eqv? fixnum-max (gcd fixnum-max 0))) | |
de142bea DH |
816 | |
817 | (pass-if "n = 1" | |
21e39e8f | 818 | (eqv? 1 (gcd fixnum-max 1))) |
de142bea DH |
819 | |
820 | (pass-if "n = -1" | |
21e39e8f DH |
821 | (eqv? 1 (gcd fixnum-max -1))) |
822 | ||
823 | (pass-if "n = fixnum-max" | |
824 | (eqv? fixnum-max (gcd fixnum-max fixnum-max))) | |
de142bea | 825 | |
21e39e8f DH |
826 | (pass-if "n = fixnum-max + 1" |
827 | (eqv? 1 (gcd fixnum-max (+ fixnum-max 1)))) | |
de142bea | 828 | |
21e39e8f DH |
829 | (pass-if "n = fixnum-min" |
830 | (eqv? 1 (gcd fixnum-max fixnum-min))) | |
de142bea | 831 | |
21e39e8f DH |
832 | (pass-if "n = fixnum-min - 1" |
833 | (eqv? 1 (gcd fixnum-max (- fixnum-min 1))))) | |
834 | ||
835 | (with-test-prefix "((+ fixnum-max 1) n)" | |
836 | ||
837 | (pass-if "n = 0" | |
838 | (eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) 0))) | |
839 | ||
840 | (pass-if "n = 1" | |
841 | (eqv? 1 (gcd (+ fixnum-max 1) 1))) | |
de142bea DH |
842 | |
843 | (pass-if "n = -1" | |
21e39e8f | 844 | (eqv? 1 (gcd (+ fixnum-max 1) -1))) |
de142bea | 845 | |
21e39e8f DH |
846 | (pass-if "n = fixnum-max" |
847 | (eqv? 1 (gcd (+ fixnum-max 1) fixnum-max))) | |
de142bea | 848 | |
21e39e8f DH |
849 | (pass-if "n = fixnum-max + 1" |
850 | (eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) (+ fixnum-max 1)))) | |
de142bea | 851 | |
21e39e8f DH |
852 | (pass-if "n = fixnum-min" |
853 | (eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) fixnum-min))) | |
854 | ||
855 | (pass-if "n = fixnum-min - 1" | |
856 | (eqv? 1 (gcd (+ fixnum-max 1) (- fixnum-min 1))))) | |
857 | ||
858 | (with-test-prefix "(fixnum-min n)" | |
859 | ||
860 | (pass-if "n = 0" | |
861 | (eqv? (- fixnum-min) (gcd fixnum-min 0))) | |
862 | ||
863 | (pass-if "n = 1" | |
864 | (eqv? 1 (gcd fixnum-min 1))) | |
de142bea DH |
865 | |
866 | (pass-if "n = -1" | |
21e39e8f DH |
867 | (eqv? 1 (gcd fixnum-min -1))) |
868 | ||
869 | (pass-if "n = fixnum-max" | |
870 | (eqv? 1 (gcd fixnum-min fixnum-max))) | |
871 | ||
872 | (pass-if "n = fixnum-max + 1" | |
873 | (eqv? (+ fixnum-max 1) (gcd fixnum-min (+ fixnum-max 1)))) | |
de142bea | 874 | |
21e39e8f DH |
875 | (pass-if "n = fixnum-min" |
876 | (eqv? (- fixnum-min) (gcd fixnum-min fixnum-min))) | |
877 | ||
878 | (pass-if "n = fixnum-min - 1" | |
879 | (eqv? 1 (gcd fixnum-min (- fixnum-min 1))))) | |
880 | ||
881 | (with-test-prefix "((- fixnum-min 1) n)" | |
882 | ||
883 | (pass-if "n = 0" | |
884 | (eqv? (- (- fixnum-min 1)) (gcd (- fixnum-min 1) 0))) | |
885 | ||
886 | (pass-if "n = 1" | |
887 | (eqv? 1 (gcd (- fixnum-min 1) 1))) | |
888 | ||
889 | (pass-if "n = -1" | |
890 | (eqv? 1 (gcd (- fixnum-min 1) -1))) | |
891 | ||
892 | (pass-if "n = fixnum-max" | |
893 | (eqv? 1 (gcd (- fixnum-min 1) fixnum-max))) | |
894 | ||
895 | (pass-if "n = fixnum-max + 1" | |
896 | (eqv? 1 (gcd (- fixnum-min 1) (+ fixnum-max 1)))) | |
897 | ||
898 | (pass-if "n = fixnum-min" | |
899 | (eqv? 1 (gcd (- fixnum-min 1) fixnum-min))) | |
900 | ||
901 | (pass-if "n = fixnum-min - 1" | |
902 | (eqv? (- (- fixnum-min 1)) (gcd (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
903 | |
904 | ;; Are wrong type arguments detected correctly? | |
905 | ||
906 | ) | |
907 | ||
f29b3454 DH |
908 | ;;; |
909 | ;;; lcm | |
910 | ;;; | |
911 | ||
7c24e528 RB |
912 | (with-test-prefix "lcm" |
913 | ;; FIXME: more tests? | |
914 | ;; (some of these are already in r4rs.test) | |
915 | (expect-fail (documented? lcm)) | |
916 | (pass-if (= (lcm) 1)) | |
917 | (pass-if (= (lcm 32 -36) 288)) | |
918 | (let ((big-n 115792089237316195423570985008687907853269984665640564039457584007913129639936) ; 2 ^ 256 | |
919 | (lcm-of-big-n-and-11 1273712981610478149659280835095566986385969831322046204434033424087044426039296)) | |
920 | (pass-if (= lcm-of-big-n-and-11 (lcm big-n 11))) | |
921 | (pass-if (= lcm-of-big-n-and-11 (lcm 11 big-n 11))))) | |
922 | ||
f29b3454 DH |
923 | ;;; |
924 | ;;; number->string | |
925 | ;;; | |
926 | ||
7c24e528 RB |
927 | (with-test-prefix "number->string" |
928 | (let ((num->str->num | |
929 | (lambda (n radix) | |
930 | (string->number (number->string n radix) radix)))) | |
931 | ||
932 | (pass-if (documented? number->string)) | |
933 | (pass-if (string=? (number->string 0) "0")) | |
934 | (pass-if (string=? (number->string 171) "171")) | |
935 | (pass-if (= (+ fixnum-max 1) (num->str->num (+ fixnum-max 1) 10))) | |
936 | (pass-if (= (- fixnum-min 1) (num->str->num (- fixnum-min 1) 10))) | |
937 | (pass-if (= (inf) (num->str->num (inf) 10))) | |
938 | (pass-if (= 1.3 (num->str->num 1.3 10))))) | |
939 | ||
f29b3454 DH |
940 | ;;; |
941 | ;;; string->number | |
942 | ;;; | |
943 | ||
2f4a254a DH |
944 | (with-test-prefix "string->number" |
945 | ||
946 | (pass-if "string->number" | |
947 | (documented? string->number)) | |
948 | ||
949 | (pass-if "non number strings" | |
950 | (for-each (lambda (x) (if (string->number x) (throw 'fail))) | |
569c483b | 951 | '("" "q" "1q" "6+7iq" "8+9q" "10+11" "13+" "18@19q" "20@q" "23@" |
2f4a254a | 952 | "+25iq" "26i" "-q" "-iq" "i" "5#.0" "8/" "10#11" ".#" "." |
569c483b | 953 | "#o.2" "3.4q" "15.16e17q" "18.19e+q" ".q" ".17#18" "10q" "#b2" |
2f4a254a DH |
954 | "#b3" "#b4" "#b5" "#b6" "#b7" "#b8" "#b9" "#ba" "#bb" "#bc" |
955 | "#bd" "#be" "#bf" "#q" "#b#b1" "#o#o1" "#d#d1" "#x#x1" "#e#e1" | |
956 | "#i#i1" "12@12+0i")) | |
957 | #t) | |
958 | ||
b7d9b1cf DH |
959 | (pass-if "valid number strings" |
960 | (for-each (lambda (couple) | |
961 | (apply | |
962 | (lambda (x y) | |
963 | (let ((x (string->number x))) | |
964 | (if (or (eq? x #f) (not (eqv? x y))) (throw 'fail)))) | |
965 | couple)) | |
966 | `(;; Radix: | |
967 | ("#b0" 0) ("#B0" 0) ("#b1" 1) ("#B1" 1) ("#o0" 0) ("#O0" 0) | |
968 | ("#o1" 1) ("#O1" 1) ("#o2" 2) ("#O2" 2) ("#o3" 3) ("#O3" 3) | |
969 | ("#o4" 4) ("#O4" 4) ("#o5" 5) ("#O5" 5) ("#o6" 6) ("#O6" 6) | |
970 | ("#o7" 7) ("#O7" 7) ("#d0" 0) ("#D0" 0) ("#d1" 1) ("#D1" 1) | |
971 | ("#d2" 2) ("#D2" 2) ("#d3" 3) ("#D3" 3) ("#d4" 4) ("#D4" 4) | |
972 | ("#d5" 5) ("#D5" 5) ("#d6" 6) ("#D6" 6) ("#d7" 7) ("#D7" 7) | |
973 | ("#d8" 8) ("#D8" 8) ("#d9" 9) ("#D9" 9) | |
974 | ("#xa" 10) ("#Xa" 10) ("#xb" 11) ("#Xb" 11) | |
975 | ("#xc" 12) ("#Xc" 12) ("#xd" 13) ("#Xd" 13) | |
976 | ("#xe" 14) ("#Xe" 14) ("#xf" 15) ("#Xf" 15) | |
977 | ("#b1010" 10) | |
978 | ("#o12345670" 2739128) | |
979 | ("#d1234567890" 1234567890) | |
980 | ("#x1234567890abcdef" 1311768467294899695) | |
981 | ;; Exactness: | |
982 | ("#e1" 1) ("#e1.2" 1) ("#i1.1" 1.1) ("#i1" 1.0) | |
983 | ;; Integers: | |
984 | ("1" ,(1+ 0)) ("23" ,(+ 9 9 5)) ("-1" ,(- 0 1)) | |
985 | ("-45" ,(- 0 45)) ("2#" 20.0) ("2##" 200.0) ("12##" 1200.0) | |
986 | ("#b#i100" 4.0) | |
987 | ;; Rationals: | |
988 | ("1/1" 1) ("1/2" 0.5) ("-1/2" -0.5) ("1#/1" 10.0) | |
989 | ("10/1#" 1.0) ("1#/1#" 1.0) ("#e9/10" 1) ("#e10/1#" 1) | |
990 | ("#i6/8" 0.75) ("#i1/1" 1.0) | |
991 | ;; Decimal numbers: | |
992 | ;; * <uinteger 10> <suffix> | |
993 | ("1e2" 100.0) ("1E2" 100.0) ("1s2" 100.0) ("1S2" 100.0) | |
994 | ("1f2" 100.0) ("1F2" 100.0) ("1d2" 100.0) ("1D2" 100.0) | |
995 | ("1l2" 100.0) ("1L2" 100.0) ("1e+2" 100.0) ("1e-2" 0.01) | |
996 | ;; * . <digit 10>+ #* <suffix> | |
997 | (".1" .1) (".0123456789" 123456789e-10) (".16#" 0.16) | |
998 | (".0123456789e10" 123456789.0) (".16#e3" 160.0) ("#d.3" 0.3) | |
999 | ;; * <digit 10>+ . <digit 10>* #* <suffix> | |
1000 | ("3." ,(exact->inexact 3)) ("3.e0" ,(exact->inexact 3)) | |
1001 | ("3.1" ,(exact->inexact 31/10)) ("3.1e0" 3.1) ("3.1#" 3.1) | |
1002 | ("3.1#e0" 3.1) | |
1003 | ;; * <digit 10>+ #+ . #* <suffix> | |
1004 | ("3#." 30.0) ("3#.e0" 30.0) ("3#.#" 30.0) ("3#.#e0" 30.0) | |
1005 | ;; Complex: | |
1006 | ("1@0" 1.0) ("1@+0" 1.0) ("1@-0" 1.0) | |
1007 | ("2+3i" ,(+ 2 (* 3 +i))) ("4-5i" ,(- 4 (* 5 +i))) | |
1008 | ("1+i" 1+1i) ("1-i" 1-1i) ("+1i" 0+1i) ("-1i" 0-1i) | |
1009 | ("+i" +1i) ("-i" -1i))) | |
1010 | #t) | |
1011 | ||
2f4a254a DH |
1012 | (pass-if-exception "exponent too big" |
1013 | exception:out-of-range | |
1014 | (string->number "12.13e141414"))) | |
1015 | ||
f29b3454 DH |
1016 | ;;; |
1017 | ;;; number? | |
1018 | ;;; | |
1019 | ||
7c24e528 RB |
1020 | (with-test-prefix "number?" |
1021 | (pass-if (documented? number?)) | |
1022 | (pass-if (number? 0)) | |
1023 | (pass-if (number? 7)) | |
1024 | (pass-if (number? -7)) | |
1025 | (pass-if (number? 1.3)) | |
1026 | (pass-if (number? (+ 1 fixnum-max))) | |
1027 | (pass-if (number? (- 1 fixnum-min))) | |
1028 | (pass-if (number? 3+4i)) | |
1029 | (expect-fail (number? #\a)) | |
1030 | (expect-fail (number? "a")) | |
1031 | (expect-fail (number? (make-vector 0))) | |
1032 | (expect-fail (number? (cons 1 2))) | |
1033 | (expect-fail (number? #t)) | |
1034 | (expect-fail (number? (lambda () #t))) | |
1035 | (expect-fail (number? (current-input-port)))) | |
1036 | ||
f29b3454 DH |
1037 | ;;; |
1038 | ;;; complex? | |
1039 | ;;; | |
1040 | ||
7c24e528 RB |
1041 | (with-test-prefix "complex?" |
1042 | (pass-if (documented? complex?)) | |
1043 | (pass-if (complex? 0)) | |
1044 | (pass-if (complex? 7)) | |
1045 | (pass-if (complex? -7)) | |
1046 | (pass-if (complex? (+ 1 fixnum-max))) | |
1047 | (pass-if (complex? (- 1 fixnum-min))) | |
1048 | (pass-if (complex? 1.3)) | |
1049 | (pass-if (complex? 3+4i)) | |
1050 | (expect-fail (complex? #\a)) | |
1051 | (expect-fail (complex? "a")) | |
1052 | (expect-fail (complex? (make-vector 0))) | |
1053 | (expect-fail (complex? (cons 1 2))) | |
1054 | (expect-fail (complex? #t)) | |
1055 | (expect-fail (complex? (lambda () #t))) | |
1056 | (expect-fail (complex? (current-input-port)))) | |
1057 | ||
f29b3454 DH |
1058 | ;;; |
1059 | ;;; real? | |
1060 | ;;; | |
1061 | ||
7c24e528 RB |
1062 | (with-test-prefix "real?" |
1063 | (pass-if (documented? real?)) | |
1064 | (pass-if (real? 0)) | |
1065 | (pass-if (real? 7)) | |
1066 | (pass-if (real? -7)) | |
1067 | (pass-if (real? (+ 1 fixnum-max))) | |
1068 | (pass-if (real? (- 1 fixnum-min))) | |
1069 | (pass-if (real? 1.3)) | |
1070 | (expect-fail (real? 3+4i)) | |
1071 | (expect-fail (real? #\a)) | |
1072 | (expect-fail (real? "a")) | |
1073 | (expect-fail (real? (make-vector 0))) | |
1074 | (expect-fail (real? (cons 1 2))) | |
1075 | (expect-fail (real? #t)) | |
1076 | (expect-fail (real? (lambda () #t))) | |
1077 | (expect-fail (real? (current-input-port)))) | |
1078 | ||
f29b3454 | 1079 | ;;; |
7c24e528 | 1080 | ;;; rational? (same as real? right now) |
f29b3454 DH |
1081 | ;;; |
1082 | ||
7c24e528 RB |
1083 | (with-test-prefix "rational?" |
1084 | (pass-if (documented? rational?)) | |
1085 | (pass-if (rational? 0)) | |
1086 | (pass-if (rational? 7)) | |
1087 | (pass-if (rational? -7)) | |
1088 | (pass-if (rational? (+ 1 fixnum-max))) | |
1089 | (pass-if (rational? (- 1 fixnum-min))) | |
1090 | (pass-if (rational? 1.3)) | |
1091 | (expect-fail (rational? 3+4i)) | |
1092 | (expect-fail (rational? #\a)) | |
1093 | (expect-fail (rational? "a")) | |
1094 | (expect-fail (rational? (make-vector 0))) | |
1095 | (expect-fail (rational? (cons 1 2))) | |
1096 | (expect-fail (rational? #t)) | |
1097 | (expect-fail (rational? (lambda () #t))) | |
1098 | (expect-fail (rational? (current-input-port)))) | |
1099 | ||
f29b3454 DH |
1100 | ;;; |
1101 | ;;; integer? | |
1102 | ;;; | |
1103 | ||
7c24e528 RB |
1104 | (with-test-prefix "integer?" |
1105 | (pass-if (documented? integer?)) | |
1106 | (pass-if (integer? 0)) | |
1107 | (pass-if (integer? 7)) | |
1108 | (pass-if (integer? -7)) | |
1109 | (pass-if (integer? (+ 1 fixnum-max))) | |
1110 | (pass-if (integer? (- 1 fixnum-min))) | |
1111 | (pass-if (and (= 3+0i (round 3+0i)) (integer? 3+0i))) | |
1112 | (pass-if (and (= 1.0 (round 1.0)) (integer? 1.0))) | |
1113 | (expect-fail (integer? 1.3)) | |
1114 | (expect-fail (integer? 3+4i)) | |
1115 | (expect-fail (integer? #\a)) | |
1116 | (expect-fail (integer? "a")) | |
1117 | (expect-fail (integer? (make-vector 0))) | |
1118 | (expect-fail (integer? (cons 1 2))) | |
1119 | (expect-fail (integer? #t)) | |
1120 | (expect-fail (integer? (lambda () #t))) | |
1121 | (expect-fail (integer? (current-input-port)))) | |
1122 | ||
f29b3454 DH |
1123 | ;;; |
1124 | ;;; inexact? | |
1125 | ;;; | |
1126 | ||
7c24e528 RB |
1127 | (with-test-prefix "inexact?" |
1128 | (pass-if (documented? inexact?)) | |
1129 | (expect-fail (inexact? 0)) | |
1130 | (expect-fail (inexact? 7)) | |
1131 | (expect-fail (inexact? -7)) | |
1132 | (expect-fail (inexact? (+ 1 fixnum-max))) | |
1133 | (expect-fail (inexact? (- 1 fixnum-min))) | |
1134 | (pass-if (inexact? 1.3)) | |
1135 | (pass-if (inexact? 3.1+4.2i)) | |
1136 | (expect-fail (inexact? #\a)) | |
1137 | (expect-fail (inexact? "a")) | |
1138 | (expect-fail (inexact? (make-vector 0))) | |
1139 | (expect-fail (inexact? (cons 1 2))) | |
1140 | (expect-fail (inexact? #t)) | |
1141 | (expect-fail (inexact? (lambda () #t))) | |
1142 | (expect-fail (inexact? (current-input-port)))) | |
1143 | ||
f29b3454 DH |
1144 | ;;; |
1145 | ;;; = | |
1146 | ;;; | |
1147 | ||
7c24e528 RB |
1148 | (with-test-prefix "=" |
1149 | (expect-fail (documented? =)) | |
1150 | (pass-if (= 0 0)) | |
1151 | (pass-if (= 7 7)) | |
1152 | (pass-if (= -7 -7)) | |
1153 | (pass-if (= (+ 1 fixnum-max) (+ 1 fixnum-max))) | |
1154 | (pass-if (= (- 1 fixnum-min) (- 1 fixnum-min))) | |
1155 | (expect-fail (= 0 1)) | |
1156 | (expect-fail (= fixnum-max (+ 1 fixnum-max))) | |
1157 | (expect-fail (= (+ 1 fixnum-max) fixnum-max)) | |
1158 | (expect-fail (= fixnum-min (- fixnum-min 1))) | |
1159 | (expect-fail (= (- fixnum-min 1) fixnum-min)) | |
1160 | (expect-fail (= (+ fixnum-max 1) (- fixnum-min 1)))) | |
1161 | ||
de142bea DH |
1162 | ;;; |
1163 | ;;; < | |
1164 | ;;; | |
1165 | ||
1166 | (with-test-prefix "<" | |
1167 | ||
de142bea | 1168 | (expect-fail "documented?" |
cb18f2a8 | 1169 | (documented? <)) |
de142bea | 1170 | |
de142bea DH |
1171 | (with-test-prefix "(< 0 n)" |
1172 | ||
1173 | (pass-if "n = 0" | |
1174 | (not (< 0 0))) | |
1175 | ||
1176 | (pass-if "n = 0.0" | |
1177 | (not (< 0 0.0))) | |
1178 | ||
1179 | (pass-if "n = 1" | |
1180 | (< 0 1)) | |
1181 | ||
1182 | (pass-if "n = 1.0" | |
1183 | (< 0 1.0)) | |
1184 | ||
1185 | (pass-if "n = -1" | |
1186 | (not (< 0 -1))) | |
1187 | ||
1188 | (pass-if "n = -1.0" | |
1189 | (not (< 0 -1.0))) | |
1190 | ||
21e39e8f DH |
1191 | (pass-if "n = fixnum-max" |
1192 | (< 0 fixnum-max)) | |
1193 | ||
1194 | (pass-if "n = fixnum-max + 1" | |
1195 | (< 0 (+ fixnum-max 1))) | |
1196 | ||
1197 | (pass-if "n = fixnum-min" | |
1198 | (not (< 0 fixnum-min))) | |
de142bea | 1199 | |
21e39e8f DH |
1200 | (pass-if "n = fixnum-min - 1" |
1201 | (not (< 0 (- fixnum-min 1))))) | |
1202 | ||
de142bea DH |
1203 | (with-test-prefix "(< 0.0 n)" |
1204 | ||
1205 | (pass-if "n = 0" | |
1206 | (not (< 0.0 0))) | |
1207 | ||
1208 | (pass-if "n = 0.0" | |
1209 | (not (< 0.0 0.0))) | |
1210 | ||
1211 | (pass-if "n = 1" | |
1212 | (< 0.0 1)) | |
1213 | ||
1214 | (pass-if "n = 1.0" | |
1215 | (< 0.0 1.0)) | |
1216 | ||
1217 | (pass-if "n = -1" | |
1218 | (not (< 0.0 -1))) | |
1219 | ||
1220 | (pass-if "n = -1.0" | |
1221 | (not (< 0.0 -1.0))) | |
1222 | ||
21e39e8f DH |
1223 | (pass-if "n = fixnum-max" |
1224 | (< 0.0 fixnum-max)) | |
1225 | ||
1226 | (pass-if "n = fixnum-max + 1" | |
1227 | (< 0.0 (+ fixnum-max 1))) | |
de142bea | 1228 | |
21e39e8f DH |
1229 | (pass-if "n = fixnum-min" |
1230 | (not (< 0.0 fixnum-min))) | |
1231 | ||
1232 | (pass-if "n = fixnum-min - 1" | |
1233 | (not (< 0.0 (- fixnum-min 1))))) | |
1234 | ||
1235 | (with-test-prefix "(< 1 n)" | |
de142bea | 1236 | |
21e39e8f | 1237 | (pass-if "n = 0" |
de142bea DH |
1238 | (not (< 1 0))) |
1239 | ||
21e39e8f DH |
1240 | (pass-if "n = 0.0" |
1241 | (not (< 1 0.0))) | |
1242 | ||
1243 | (pass-if "n = 1" | |
1244 | (not (< 1 1))) | |
1245 | ||
de142bea | 1246 | (pass-if "n = 1.0" |
21e39e8f DH |
1247 | (not (< 1 1.0))) |
1248 | ||
1249 | (pass-if "n = -1" | |
1250 | (not (< 1 -1))) | |
1251 | ||
1252 | (pass-if "n = -1.0" | |
1253 | (not (< 1 -1.0))) | |
1254 | ||
1255 | (pass-if "n = fixnum-max" | |
1256 | (< 1 fixnum-max)) | |
1257 | ||
1258 | (pass-if "n = fixnum-max + 1" | |
1259 | (< 1 (+ fixnum-max 1))) | |
1260 | ||
1261 | (pass-if "n = fixnum-min" | |
1262 | (not (< 1 fixnum-min))) | |
1263 | ||
1264 | (pass-if "n = fixnum-min - 1" | |
1265 | (not (< 1 (- fixnum-min 1))))) | |
1266 | ||
1267 | (with-test-prefix "(< 1.0 n)" | |
1268 | ||
1269 | (pass-if "n = 0" | |
de142bea DH |
1270 | (not (< 1.0 0))) |
1271 | ||
21e39e8f DH |
1272 | (pass-if "n = 0.0" |
1273 | (not (< 1.0 0.0))) | |
1274 | ||
1275 | (pass-if "n = 1" | |
1276 | (not (< 1.0 1))) | |
1277 | ||
1278 | (pass-if "n = 1.0" | |
1279 | (not (< 1.0 1.0))) | |
1280 | ||
de142bea | 1281 | (pass-if "n = -1" |
21e39e8f DH |
1282 | (not (< 1.0 -1))) |
1283 | ||
1284 | (pass-if "n = -1.0" | |
1285 | (not (< 1.0 -1.0))) | |
1286 | ||
1287 | (pass-if "n = fixnum-max" | |
1288 | (< 1.0 fixnum-max)) | |
1289 | ||
1290 | (pass-if "n = fixnum-max + 1" | |
1291 | (< 1.0 (+ fixnum-max 1))) | |
1292 | ||
1293 | (pass-if "n = fixnum-min" | |
1294 | (not (< 1.0 fixnum-min))) | |
1295 | ||
1296 | (pass-if "n = fixnum-min - 1" | |
1297 | (not (< 1.0 (- fixnum-min 1))))) | |
1298 | ||
1299 | (with-test-prefix "(< -1 n)" | |
1300 | ||
1301 | (pass-if "n = 0" | |
de142bea DH |
1302 | (< -1 0)) |
1303 | ||
21e39e8f DH |
1304 | (pass-if "n = 0.0" |
1305 | (< -1 0.0)) | |
1306 | ||
1307 | (pass-if "n = 1" | |
1308 | (< -1 1)) | |
1309 | ||
1310 | (pass-if "n = 1.0" | |
1311 | (< -1 1.0)) | |
1312 | ||
1313 | (pass-if "n = -1" | |
1314 | (not (< -1 -1))) | |
1315 | ||
de142bea | 1316 | (pass-if "n = -1.0" |
21e39e8f DH |
1317 | (not (< -1 -1.0))) |
1318 | ||
1319 | (pass-if "n = fixnum-max" | |
1320 | (< -1 fixnum-max)) | |
1321 | ||
1322 | (pass-if "n = fixnum-max + 1" | |
1323 | (< -1 (+ fixnum-max 1))) | |
1324 | ||
1325 | (pass-if "n = fixnum-min" | |
1326 | (not (< -1 fixnum-min))) | |
1327 | ||
1328 | (pass-if "n = fixnum-min - 1" | |
1329 | (not (< -1 (- fixnum-min 1))))) | |
1330 | ||
1331 | (with-test-prefix "(< -1.0 n)" | |
1332 | ||
1333 | (pass-if "n = 0" | |
de142bea DH |
1334 | (< -1.0 0)) |
1335 | ||
21e39e8f DH |
1336 | (pass-if "n = 0.0" |
1337 | (< -1.0 0.0)) | |
1338 | ||
1339 | (pass-if "n = 1" | |
1340 | (< -1.0 1)) | |
1341 | ||
1342 | (pass-if "n = 1.0" | |
1343 | (< -1.0 1.0)) | |
1344 | ||
1345 | (pass-if "n = -1" | |
1346 | (not (< -1.0 -1))) | |
1347 | ||
1348 | (pass-if "n = -1.0" | |
1349 | (not (< -1.0 -1.0))) | |
1350 | ||
1351 | (pass-if "n = fixnum-max" | |
1352 | (< -1.0 fixnum-max)) | |
1353 | ||
1354 | (pass-if "n = fixnum-max + 1" | |
1355 | (< -1.0 (+ fixnum-max 1))) | |
de142bea | 1356 | |
21e39e8f DH |
1357 | (pass-if "n = fixnum-min" |
1358 | (not (< -1.0 fixnum-min))) | |
1359 | ||
1360 | (pass-if "n = fixnum-min - 1" | |
1361 | (not (< -1.0 (- fixnum-min 1))))) | |
1362 | ||
1363 | (with-test-prefix "(< fixnum-max n)" | |
1364 | ||
1365 | (pass-if "n = 0" | |
1366 | (not (< fixnum-max 0))) | |
1367 | ||
1368 | (pass-if "n = 0.0" | |
1369 | (not (< fixnum-max 0.0))) | |
de142bea DH |
1370 | |
1371 | (pass-if "n = 1" | |
21e39e8f | 1372 | (not (< fixnum-max 1))) |
de142bea DH |
1373 | |
1374 | (pass-if "n = 1.0" | |
21e39e8f | 1375 | (not (< fixnum-max 1.0))) |
de142bea DH |
1376 | |
1377 | (pass-if "n = -1" | |
21e39e8f | 1378 | (not (< fixnum-max -1))) |
de142bea DH |
1379 | |
1380 | (pass-if "n = -1.0" | |
21e39e8f | 1381 | (not (< fixnum-max -1.0))) |
de142bea | 1382 | |
21e39e8f DH |
1383 | (pass-if "n = fixnum-max" |
1384 | (not (< fixnum-max fixnum-max))) | |
de142bea | 1385 | |
21e39e8f DH |
1386 | (pass-if "n = fixnum-max + 1" |
1387 | (< fixnum-max (+ fixnum-max 1))) | |
1388 | ||
1389 | (pass-if "n = fixnum-min" | |
1390 | (not (< fixnum-max fixnum-min))) | |
1391 | ||
1392 | (pass-if "n = fixnum-min - 1" | |
1393 | (not (< fixnum-max (- fixnum-min 1))))) | |
1394 | ||
1395 | (with-test-prefix "(< (+ fixnum-max 1) n)" | |
1396 | ||
1397 | (pass-if "n = 0" | |
1398 | (not (< (+ fixnum-max 1) 0))) | |
1399 | ||
1400 | (pass-if "n = 0.0" | |
1401 | (not (< (+ fixnum-max 1) 0.0))) | |
de142bea DH |
1402 | |
1403 | (pass-if "n = 1" | |
21e39e8f | 1404 | (not (< (+ fixnum-max 1) 1))) |
de142bea DH |
1405 | |
1406 | (pass-if "n = 1.0" | |
21e39e8f | 1407 | (not (< (+ fixnum-max 1) 1.0))) |
de142bea DH |
1408 | |
1409 | (pass-if "n = -1" | |
21e39e8f | 1410 | (not (< (+ fixnum-max 1) -1))) |
de142bea DH |
1411 | |
1412 | (pass-if "n = -1.0" | |
21e39e8f | 1413 | (not (< (+ fixnum-max 1) -1.0))) |
de142bea | 1414 | |
21e39e8f DH |
1415 | (pass-if "n = fixnum-max" |
1416 | (not (< (+ fixnum-max 1) fixnum-max))) | |
de142bea | 1417 | |
21e39e8f DH |
1418 | (pass-if "n = fixnum-max + 1" |
1419 | (not (< (+ fixnum-max 1) (+ fixnum-max 1)))) | |
de142bea | 1420 | |
21e39e8f DH |
1421 | (pass-if "n = fixnum-min" |
1422 | (not (< (+ fixnum-max 1) fixnum-min))) | |
1423 | ||
1424 | (pass-if "n = fixnum-min - 1" | |
1425 | (not (< (+ fixnum-max 1) (- fixnum-min 1))))) | |
1426 | ||
1427 | (with-test-prefix "(< fixnum-min n)" | |
1428 | ||
1429 | (pass-if "n = 0" | |
1430 | (< fixnum-min 0)) | |
1431 | ||
1432 | (pass-if "n = 0.0" | |
1433 | (< fixnum-min 0.0)) | |
de142bea DH |
1434 | |
1435 | (pass-if "n = 1" | |
21e39e8f | 1436 | (< fixnum-min 1)) |
de142bea DH |
1437 | |
1438 | (pass-if "n = 1.0" | |
21e39e8f | 1439 | (< fixnum-min 1.0)) |
de142bea DH |
1440 | |
1441 | (pass-if "n = -1" | |
21e39e8f | 1442 | (< fixnum-min -1)) |
de142bea DH |
1443 | |
1444 | (pass-if "n = -1.0" | |
21e39e8f | 1445 | (< fixnum-min -1.0)) |
de142bea | 1446 | |
21e39e8f DH |
1447 | (pass-if "n = fixnum-max" |
1448 | (< fixnum-min fixnum-max)) | |
1449 | ||
1450 | (pass-if "n = fixnum-max + 1" | |
1451 | (< fixnum-min (+ fixnum-max 1))) | |
de142bea | 1452 | |
21e39e8f DH |
1453 | (pass-if "n = fixnum-min" |
1454 | (not (< fixnum-min fixnum-min))) | |
de142bea | 1455 | |
21e39e8f DH |
1456 | (pass-if "n = fixnum-min - 1" |
1457 | (not (< fixnum-min (- fixnum-min 1))))) | |
1458 | ||
1459 | (with-test-prefix "(< (- fixnum-min 1) n)" | |
1460 | ||
1461 | (pass-if "n = 0" | |
1462 | (< (- fixnum-min 1) 0)) | |
1463 | ||
1464 | (pass-if "n = 0.0" | |
1465 | (< (- fixnum-min 1) 0.0)) | |
1466 | ||
1467 | (pass-if "n = 1" | |
1468 | (< (- fixnum-min 1) 1)) | |
1469 | ||
1470 | (pass-if "n = 1.0" | |
1471 | (< (- fixnum-min 1) 1.0)) | |
de142bea DH |
1472 | |
1473 | (pass-if "n = -1" | |
21e39e8f | 1474 | (< (- fixnum-min 1) -1)) |
de142bea DH |
1475 | |
1476 | (pass-if "n = -1.0" | |
21e39e8f DH |
1477 | (< (- fixnum-min 1) -1.0)) |
1478 | ||
1479 | (pass-if "n = fixnum-max" | |
1480 | (< (- fixnum-min 1) fixnum-max)) | |
1481 | ||
1482 | (pass-if "n = fixnum-max + 1" | |
1483 | (< (- fixnum-min 1) (+ fixnum-max 1))) | |
1484 | ||
1485 | (pass-if "n = fixnum-min" | |
1486 | (< (- fixnum-min 1) fixnum-min)) | |
1487 | ||
1488 | (pass-if "n = fixnum-min - 1" | |
1489 | (not (< (- fixnum-min 1) (- fixnum-min 1)))))) | |
f29b3454 DH |
1490 | |
1491 | ;;; | |
1492 | ;;; > | |
1493 | ;;; | |
1494 | ||
7c24e528 RB |
1495 | ;; currently not tested -- implementation is trivial |
1496 | ;; (> x y) is implemented as (< y x) | |
1497 | ;; FIXME: tests should probably be added in case we change implementation. | |
1498 | ||
f29b3454 DH |
1499 | ;;; |
1500 | ;;; <= | |
1501 | ;;; | |
1502 | ||
7c24e528 RB |
1503 | ;; currently not tested -- implementation is trivial |
1504 | ;; (<= x y) is implemented as (not (< y x)) | |
1505 | ;; FIXME: tests should probably be added in case we change implementation. | |
1506 | ||
f29b3454 DH |
1507 | ;;; |
1508 | ;;; >= | |
1509 | ;;; | |
1510 | ||
7c24e528 RB |
1511 | ;; currently not tested -- implementation is trivial |
1512 | ;; (>= x y) is implemented as (not (< x y)) | |
1513 | ;; FIXME: tests should probably be added in case we change implementation. | |
1514 | ||
f29b3454 DH |
1515 | ;;; |
1516 | ;;; zero? | |
1517 | ;;; | |
1518 | ||
7c24e528 RB |
1519 | (with-test-prefix "zero?" |
1520 | (expect-fail (documented? zero?)) | |
1521 | (pass-if (zero? 0)) | |
1522 | (expect-fail (zero? 7)) | |
1523 | (expect-fail (zero? -7)) | |
1524 | (expect-fail (zero? (+ 1 fixnum-max))) | |
1525 | (expect-fail (zero? (- 1 fixnum-min))) | |
1526 | (expect-fail (zero? 1.3)) | |
1527 | (expect-fail (zero? 3.1+4.2i))) | |
1528 | ||
f29b3454 DH |
1529 | ;;; |
1530 | ;;; positive? | |
1531 | ;;; | |
1532 | ||
7c24e528 RB |
1533 | (with-test-prefix "positive?" |
1534 | (expect-fail (documented? positive?)) | |
1535 | (pass-if (positive? 1)) | |
1536 | (pass-if (positive? (+ fixnum-max 1))) | |
1537 | (pass-if (positive? 1.3)) | |
1538 | (expect-fail (positive? 0)) | |
1539 | (expect-fail (positive? -1)) | |
1540 | (expect-fail (positive? (- fixnum-min 1))) | |
1541 | (expect-fail (positive? -1.3))) | |
1542 | ||
f29b3454 DH |
1543 | ;;; |
1544 | ;;; negative? | |
1545 | ;;; | |
1546 | ||
7c24e528 RB |
1547 | (with-test-prefix "negative?" |
1548 | (expect-fail (documented? negative?)) | |
1549 | (expect-fail (negative? 1)) | |
1550 | (expect-fail (negative? (+ fixnum-max 1))) | |
1551 | (expect-fail (negative? 1.3)) | |
1552 | (expect-fail (negative? 0)) | |
1553 | (pass-if (negative? -1)) | |
1554 | (pass-if (negative? (- fixnum-min 1))) | |
1555 | (pass-if (negative? -1.3))) | |
1556 | ||
f29b3454 DH |
1557 | ;;; |
1558 | ;;; max | |
1559 | ;;; | |
1560 | ||
1561 | ;;; | |
1562 | ;;; min | |
1563 | ;;; | |
1564 | ||
7c24e528 RB |
1565 | ;; FIXME: unfinished... |
1566 | ||
1567 | (with-test-prefix "min" | |
1568 | (let ((big*2 (* fixnum-max 2)) | |
1569 | (big*3 (* fixnum-max 3)) | |
1570 | (big*4 (* fixnum-max 4)) | |
1571 | (big*5 (* fixnum-max 5))) | |
1572 | ||
1573 | (expect-fail (documented? max)) | |
1574 | (pass-if (= 1 (min 7 3 1 5))) | |
1575 | (pass-if (= 1 (min 1 7 3 5))) | |
1576 | (pass-if (= 1 (min 7 3 5 1))) | |
1577 | (pass-if (= -7 (min 2 3 4 -2 5 -7 1 -1 4 2))) | |
1578 | (pass-if (= -7 (min -7 2 3 4 -2 5 1 -1 4 2))) | |
1579 | (pass-if (= -7 (min 2 3 4 -2 5 1 -1 4 2 -7))) | |
1580 | (pass-if (= big*2 (min big*3 big*5 big*2 big*4))) | |
1581 | (pass-if (= big*2 (min big*2 big*3 big*5 big*4))) | |
1582 | (pass-if (= big*2 (min big*3 big*5 big*4 big*2))) | |
1583 | (pass-if | |
1584 | (= (- fixnum-min 1) (min 2 4 (- fixnum-min 1) 3 (* 2 fixnum-max)))) | |
1585 | (pass-if | |
1586 | (= (- fixnum-min 1) (min (- fixnum-min 1) 2 4 3 (* 2 fixnum-max)))) | |
1587 | (pass-if | |
1588 | (= (- fixnum-min 1) (min 2 4 3 (* 2 fixnum-max) (- fixnum-min 1)))))) | |
1589 | ||
f29b3454 DH |
1590 | ;;; |
1591 | ;;; + | |
1592 | ;;; | |
1593 | ||
1594 | (with-test-prefix "+" | |
1595 | ||
1596 | (expect-fail "documented?" | |
1597 | (documented? +)) | |
1598 | ||
1599 | (with-test-prefix "wrong type argument" | |
1600 | ||
1601 | (pass-if-exception "1st argument string" | |
1602 | exception:wrong-type-arg | |
1603 | (+ "1" 2)) | |
1604 | ||
1605 | (pass-if-exception "2nd argument bool" | |
1606 | exception:wrong-type-arg | |
1607 | (+ 1 #f)))) | |
1608 | ;;; | |
1609 | ;;; - | |
1610 | ;;; | |
1611 | ||
1612 | ;;; | |
1613 | ;;; * | |
1614 | ;;; | |
1615 | ||
1616 | ;;; | |
1617 | ;;; / | |
1618 | ;;; | |
1619 | ||
1b3a7932 DH |
1620 | (with-test-prefix "/" |
1621 | ||
1622 | (expect-fail "documented?" | |
1623 | (documented? /)) | |
1624 | ||
1625 | (with-test-prefix "division by zero" | |
1626 | ||
1627 | (pass-if-exception "(/ 0)" | |
1628 | exception:numerical-overflow | |
1629 | (/ 0)) | |
1630 | ||
cdf52e3d MV |
1631 | (pass-if "(/ 0.0)" |
1632 | (= +inf.0 (/ 0.0))) | |
80074d77 | 1633 | |
1b3a7932 DH |
1634 | (pass-if-exception "(/ 1 0)" |
1635 | exception:numerical-overflow | |
80074d77 DH |
1636 | (/ 1 0)) |
1637 | ||
cdf52e3d MV |
1638 | (pass-if "(/ 1 0.0)" |
1639 | (= +inf.0 (/ 1 0.0))) | |
80074d77 DH |
1640 | |
1641 | (pass-if-exception "(/ bignum 0)" | |
1642 | exception:numerical-overflow | |
1643 | (/ (+ fixnum-max 1) 0)) | |
1644 | ||
cdf52e3d MV |
1645 | (pass-if "(/ bignum 0.0)" |
1646 | (= +inf.0 (/ (+ fixnum-max 1) 0.0))) | |
80074d77 DH |
1647 | |
1648 | (pass-if-exception "(/ 1.0 0)" | |
1649 | exception:numerical-overflow | |
1650 | (/ 1.0 0)) | |
1651 | ||
cdf52e3d MV |
1652 | (pass-if "(/ 1.0 0.0)" |
1653 | (= +inf.0 (/ 1.0 0.0))) | |
80074d77 DH |
1654 | |
1655 | (pass-if-exception "(/ +i 0)" | |
1656 | exception:numerical-overflow | |
1657 | (/ +i 0)) | |
1658 | ||
cdf52e3d MV |
1659 | (pass-if "(/ +i 0.0)" |
1660 | (= +inf.0 (imag-part (/ +i 0.0))))) | |
469b963c MV |
1661 | |
1662 | (with-test-prefix "complex division" | |
1663 | ||
1664 | (pass-if "(/ 3+4i)" | |
1665 | (= (/ 3+4i) 0.12-0.16i)) | |
1666 | ||
1667 | (pass-if "(/ 4+3i)" | |
1668 | (= (/ 4+3i) 0.16-0.12i)) | |
1669 | ||
1670 | (pass-if "(/ 25+125i 3+4i)" | |
1671 | (= (/ 25+125i 3+4i) 23.0+11.0i)) | |
1672 | ||
1673 | (pass-if "(/ 25+125i 4+3i)" | |
1674 | (= (/ 25+125i 4+3i) 19.0+17.0i)) | |
1675 | ||
1676 | (pass-if "(/ 25 3+4i)" | |
1677 | (= (/ 25 3+4i) 3.0-4.0i)) | |
1678 | ||
1679 | (pass-if "(/ 25 4+3i)" | |
1680 | (= (/ 25 4+3i) 4.0-3.0i)) | |
1681 | ||
1682 | (pass-if "(/ 1e200+1e200i)" | |
1683 | (= (/ 1e200+1e200i) 5.0e-201-5.0e-201i)))) | |
1b3a7932 | 1684 | |
f29b3454 DH |
1685 | ;;; |
1686 | ;;; truncate | |
1687 | ;;; | |
1688 | ||
1689 | ;;; | |
1690 | ;;; round | |
1691 | ;;; | |
1692 | ||
1693 | ;;; | |
1694 | ;;; exact->inexact | |
1695 | ;;; | |
1696 | ||
1697 | ;;; | |
1698 | ;;; floor | |
1699 | ;;; | |
1700 | ||
1701 | ;;; | |
1702 | ;;; ceiling | |
1703 | ;;; | |
1704 | ||
46f2c0f1 RB |
1705 | ;;; |
1706 | ;;; expt | |
1707 | ;;; | |
1708 | ||
1709 | (with-test-prefix "expt" | |
1710 | (pass-if "(= 1 (expt 0 0))" (= 1 (expt 0 0))) | |
1711 | (pass-if "(= 1 (expt 0 0.0))" (= 1 (expt 0 0.0))) | |
1712 | (pass-if "(= 1 (expt 0.0 0))" (= 1 (expt 0.0 0))) | |
1713 | (pass-if "(= 1 (expt 0.0 0.0))" (= 1 (expt 0.0 0.0)))) | |
1714 | ||
f29b3454 DH |
1715 | ;;; |
1716 | ;;; make-rectangular | |
1717 | ;;; | |
1718 | ||
1719 | ;;; | |
1720 | ;;; make-polar | |
1721 | ;;; | |
1722 | ||
1723 | ;;; | |
1724 | ;;; real-part | |
1725 | ;;; | |
1726 | ||
1727 | ;;; | |
1728 | ;;; imag-part | |
1729 | ;;; | |
1730 | ||
1731 | ;;; | |
1732 | ;;; magnitude | |
1733 | ;;; | |
1734 | ||
1735 | ;;; | |
1736 | ;;; angle | |
1737 | ;;; | |
1738 | ||
1739 | ;;; | |
1740 | ;;; inexact->exact | |
1741 | ;;; |