Commit | Line | Data |
---|---|---|
de142bea | 1 | ;;;; numbers.test --- tests guile's numbers -*- scheme -*- |
8e43ed5d | 2 | ;;;; Copyright (C) 2000, 2001, 2003, 2004, 2005, 2006, 2009, 2010, 2011 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 | |
53befeb7 | 7 | ;;;; version 3 of the License, or (at your option) any later version. |
73be1d9e MV |
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 | |
92205699 | 16 | ;;;; Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
de142bea | 17 | |
a1fb3b1c KR |
18 | (define-module (test-suite test-numbers) |
19 | #:use-module (test-suite lib) | |
ff62c168 | 20 | #:use-module (ice-9 documentation) |
a8591a55 | 21 | #:use-module (srfi srfi-1) ; list library |
ff62c168 | 22 | #:use-module (srfi srfi-11)) ; let-values |
de142bea | 23 | |
de142bea DH |
24 | ;;; |
25 | ;;; miscellaneous | |
26 | ;;; | |
27 | ||
1b3a7932 DH |
28 | (define exception:numerical-overflow |
29 | (cons 'numerical-overflow "^Numerical overflow")) | |
30 | ||
cb18f2a8 | 31 | (define (documented? object) |
5c96bc39 | 32 | (not (not (object-documentation object)))) |
de142bea | 33 | |
8b7838b5 RB |
34 | (define fixnum-bit |
35 | (inexact->exact (+ (/ (log (+ most-positive-fixnum 1)) (log 2)) 1))) | |
36 | ||
21e39e8f DH |
37 | (define fixnum-min most-negative-fixnum) |
38 | (define fixnum-max most-positive-fixnum) | |
de142bea | 39 | |
a1fb3b1c KR |
40 | ;; Divine the number of bits in the mantissa of a flonum. |
41 | ;; We look for when 2.0^i+1.0 gets rounded, ie. the difference between that | |
42 | ;; value and 2.0^k is not 1.0. | |
43 | ;; Of course this assumes flonums have a fixed precision mantissa, but | |
44 | ;; that's the case now and probably into the forseeable future. | |
45 | ;; On an IEEE system, which means pretty much everywhere, the value here is | |
46 | ;; the usual 53. | |
47 | ;; | |
48 | (define dbl-mant-dig | |
49 | (let more ((i 1) | |
50 | (d 2.0)) | |
51 | (if (> i 1024) | |
52 | (error "Oops, cannot determine number of bits in mantissa of inexact")) | |
53 | (let* ((sum (+ 1.0 d)) | |
54 | (diff (- sum d))) | |
55 | (if (= diff 1.0) | |
56 | (more (1+ i) (* 2.0 d)) | |
57 | i)))) | |
58 | ||
59 | ;; like ash, but working on a flonum | |
60 | (define (ash-flo x n) | |
61 | (while (> n 0) | |
62 | (set! x (* 2.0 x)) | |
63 | (set! n (1- n))) | |
64 | (while (< n 0) | |
65 | (set! x (* 0.5 x)) | |
66 | (set! n (1+ n))) | |
67 | x) | |
49579cbd KR |
68 | |
69 | ;; `quotient' but rounded towards -infinity, like `modulo' or `ash' do | |
70 | ;; note only positive D supported (that's all that's currently required) | |
71 | (define-public (quotient-floor n d) | |
72 | (if (negative? n) | |
73 | (quotient (- n d -1) d) ;; neg/pos | |
74 | (quotient n d))) ;; pos/pos | |
75 | ||
8ab3d8a0 KR |
76 | ;; return true of X is in the range LO to HI, inclusive |
77 | (define (within-range? lo hi x) | |
78 | (and (>= x (min lo hi)) | |
79 | (<= x (max lo hi)))) | |
80 | ||
81 | ;; return true if GOT is within +/- 0.01 of GOT | |
82 | ;; for a complex number both real and imaginary parts must be in that range | |
83 | (define (eqv-loosely? want got) | |
84 | (and (within-range? (- (real-part want) 0.01) | |
85 | (+ (real-part want) 0.01) | |
86 | (real-part got)) | |
87 | (within-range? (- (imag-part want) 0.01) | |
88 | (+ (imag-part want) 0.01) | |
89 | (imag-part got)))) | |
90 | ||
91 | ;; return true if OBJ is negative infinity | |
92 | (define (negative-infinity? obj) | |
93 | (and (real? obj) | |
94 | (negative? obj) | |
95 | (inf? obj))) | |
96 | ||
ff62c168 MW |
97 | ;; |
98 | ;; Tolerance used by test-eqv? for inexact numbers. | |
99 | ;; | |
100 | (define test-epsilon 1e-10) | |
101 | ||
102 | ;; | |
103 | ;; Like eqv?, except that inexact finite numbers need only be within | |
a8591a55 MW |
104 | ;; test-epsilon (1e-10) to be considered equal. For non-real complex |
105 | ;; numbers, each component is tested according to these rules. The | |
106 | ;; intent is that the known-correct value will be the first parameter. | |
ff62c168 MW |
107 | ;; |
108 | (define (test-eqv? x y) | |
109 | (cond ((real? x) | |
110 | (and (real? y) (test-real-eqv? x y))) | |
111 | ((complex? x) | |
112 | (and (not (real? y)) | |
113 | (test-real-eqv? (real-part x) (real-part y)) | |
114 | (test-real-eqv? (imag-part x) (imag-part y)))) | |
115 | (else (eqv? x y)))) | |
116 | ||
117 | ;; Auxiliary predicate used by test-eqv? | |
118 | (define (test-real-eqv? x y) | |
a8591a55 | 119 | (cond ((or (exact? x) (nan? x) (inf? x)) |
ff62c168 MW |
120 | (eqv? x y)) |
121 | (else (and (inexact? y) (> test-epsilon (abs (- x y))))))) | |
122 | ||
55a8b708 MW |
123 | ;; return true if OBJ is a real NaN |
124 | (define (real-nan? obj) | |
125 | (and (real? obj) | |
126 | (nan? obj))) | |
127 | ||
c7218482 MW |
128 | ;; return true if OBJ is a non-real complex number |
129 | ;; whose real part is a nan, and whose imaginary | |
130 | ;; part is an inexact zero. | |
131 | (define (almost-real-nan? obj) | |
132 | (and (not (real? obj)) | |
133 | (nan? (real-part obj)) | |
134 | (zero? (imag-part obj)))) | |
135 | ||
55a8b708 MW |
136 | ;; return true if both the real and imaginary |
137 | ;; parts of OBJ are NaNs | |
138 | (define (complex-nan? obj) | |
139 | (and (nan? (real-part obj)) | |
140 | (nan? (imag-part obj)))) | |
141 | ||
142 | ;; return true if the real part of OBJ is zero | |
143 | ;; and the imaginary part is a NaN. | |
144 | (define (imaginary-nan? obj) | |
145 | (and (zero? (real-part obj)) | |
146 | (nan? (imag-part obj)))) | |
147 | ||
c7218482 MW |
148 | ;; return true if OBJ is a non-real complex zero |
149 | (define (complex-zero? obj) | |
150 | (and (zero? obj) | |
151 | (complex? obj) | |
152 | (not (real? obj)))) | |
153 | ||
8ab3d8a0 KR |
154 | (define const-e 2.7182818284590452354) |
155 | (define const-e^2 7.3890560989306502274) | |
156 | (define const-1/e 0.3678794411714423215) | |
157 | ||
158 | ||
a580ebba KR |
159 | ;;; |
160 | ;;; 1+ | |
161 | ;;; | |
162 | ||
f13f1e9f | 163 | (with-test-prefix/c&e "1+" |
a580ebba KR |
164 | |
165 | (pass-if "documented?" | |
166 | (documented? 1+)) | |
167 | ||
f13f1e9f LC |
168 | (pass-if "0" (eqv? 1 (1+ 0))) |
169 | (pass-if "-1" (eqv? 0 (1+ -1))) | |
170 | (pass-if "100" (eqv? 101 (1+ 100))) | |
171 | (pass-if "-100" (eqv? -99 (1+ -100))) | |
e78d4bf9 LC |
172 | |
173 | ;; The maximum fixnum on a 32-bit architecture: 2^29 - 1. | |
f13f1e9f LC |
174 | (pass-if "1+ fixnum = bignum (32-bit)" |
175 | (eqv? 536870912 (1+ 536870911))) | |
e78d4bf9 LC |
176 | |
177 | ;; The maximum fixnum on a 64-bit architecture: 2^61 - 1. | |
f13f1e9f LC |
178 | (pass-if "1+ fixnum = bignum (64-bit)" |
179 | (eqv? 2305843009213693952 (1+ 2305843009213693951)))) | |
a580ebba KR |
180 | |
181 | ;;; | |
182 | ;;; 1- | |
183 | ;;; | |
184 | ||
f13f1e9f | 185 | (with-test-prefix/c&e "1-" |
a580ebba KR |
186 | |
187 | (pass-if "documented?" | |
188 | (documented? 1-)) | |
189 | ||
f13f1e9f LC |
190 | (pass-if "0" (eqv? -1 (1- 0))) |
191 | (pass-if "1" (eqv? 0 (1- 1))) | |
192 | (pass-if "100" (eqv? 99 (1- 100))) | |
193 | (pass-if "-100" (eqv? -101 (1- -100))) | |
e78d4bf9 LC |
194 | |
195 | ;; The minimum fixnum on a 32-bit architecture: -2^29. | |
f13f1e9f LC |
196 | (pass-if "1- fixnum = bignum (32-bit)" |
197 | (eqv? -536870913 (1- -536870912))) | |
e78d4bf9 LC |
198 | |
199 | ;; The minimum fixnum on a 64-bit architecture: -2^61. | |
f13f1e9f LC |
200 | (pass-if "1- fixnum = bignum (64-bit)" |
201 | (eqv? -2305843009213693953 (1- -2305843009213693952)))) | |
a580ebba | 202 | |
49579cbd KR |
203 | ;;; |
204 | ;;; ash | |
205 | ;;; | |
206 | ||
207 | (with-test-prefix "ash" | |
208 | ||
209 | (pass-if "documented?" | |
210 | (documented? ash)) | |
211 | ||
212 | (pass-if (eqv? 0 (ash 0 0))) | |
213 | (pass-if (eqv? 0 (ash 0 1))) | |
214 | (pass-if (eqv? 0 (ash 0 1000))) | |
215 | (pass-if (eqv? 0 (ash 0 -1))) | |
216 | (pass-if (eqv? 0 (ash 0 -1000))) | |
217 | ||
218 | (pass-if (eqv? 1 (ash 1 0))) | |
219 | (pass-if (eqv? 2 (ash 1 1))) | |
220 | (pass-if (eqv? 340282366920938463463374607431768211456 (ash 1 128))) | |
221 | (pass-if (eqv? 0 (ash 1 -1))) | |
222 | (pass-if (eqv? 0 (ash 1 -1000))) | |
223 | ||
224 | (pass-if (eqv? -1 (ash -1 0))) | |
225 | (pass-if (eqv? -2 (ash -1 1))) | |
226 | (pass-if (eqv? -340282366920938463463374607431768211456 (ash -1 128))) | |
227 | (pass-if (eqv? -1 (ash -1 -1))) | |
228 | (pass-if (eqv? -1 (ash -1 -1000))) | |
229 | ||
230 | (pass-if (eqv? -3 (ash -3 0))) | |
231 | (pass-if (eqv? -6 (ash -3 1))) | |
232 | (pass-if (eqv? -1020847100762815390390123822295304634368 (ash -3 128))) | |
233 | (pass-if (eqv? -2 (ash -3 -1))) | |
234 | (pass-if (eqv? -1 (ash -3 -1000))) | |
235 | ||
236 | (pass-if (eqv? -6 (ash -23 -2))) | |
237 | ||
238 | (pass-if (eqv? most-positive-fixnum (ash most-positive-fixnum 0))) | |
239 | (pass-if (eqv? (* 2 most-positive-fixnum) (ash most-positive-fixnum 1))) | |
240 | (pass-if (eqv? (* 4 most-positive-fixnum) (ash most-positive-fixnum 2))) | |
241 | (pass-if | |
242 | (eqv? (* most-positive-fixnum 340282366920938463463374607431768211456) | |
243 | (ash most-positive-fixnum 128))) | |
244 | (pass-if (eqv? (quotient most-positive-fixnum 2) | |
245 | (ash most-positive-fixnum -1))) | |
246 | (pass-if (eqv? 0 (ash most-positive-fixnum -1000))) | |
247 | ||
248 | (let ((mpf4 (quotient most-positive-fixnum 4))) | |
249 | (pass-if (eqv? (* 2 mpf4) (ash mpf4 1))) | |
250 | (pass-if (eqv? (* 4 mpf4) (ash mpf4 2))) | |
251 | (pass-if (eqv? (* 8 mpf4) (ash mpf4 3)))) | |
252 | ||
253 | (pass-if (eqv? most-negative-fixnum (ash most-negative-fixnum 0))) | |
254 | (pass-if (eqv? (* 2 most-negative-fixnum) (ash most-negative-fixnum 1))) | |
255 | (pass-if (eqv? (* 4 most-negative-fixnum) (ash most-negative-fixnum 2))) | |
256 | (pass-if | |
257 | (eqv? (* most-negative-fixnum 340282366920938463463374607431768211456) | |
258 | (ash most-negative-fixnum 128))) | |
259 | (pass-if (eqv? (quotient-floor most-negative-fixnum 2) | |
260 | (ash most-negative-fixnum -1))) | |
261 | (pass-if (eqv? -1 (ash most-negative-fixnum -1000))) | |
262 | ||
263 | (let ((mnf4 (quotient-floor most-negative-fixnum 4))) | |
264 | (pass-if (eqv? (* 2 mnf4) (ash mnf4 1))) | |
265 | (pass-if (eqv? (* 4 mnf4) (ash mnf4 2))) | |
266 | (pass-if (eqv? (* 8 mnf4) (ash mnf4 3))))) | |
a1fb3b1c | 267 | |
de142bea DH |
268 | ;;; |
269 | ;;; exact? | |
270 | ;;; | |
271 | ||
272 | (with-test-prefix "exact?" | |
273 | ||
de142bea | 274 | (pass-if "documented?" |
cb18f2a8 | 275 | (documented? exact?)) |
de142bea | 276 | |
21e39e8f | 277 | (with-test-prefix "integers" |
de142bea | 278 | |
21e39e8f DH |
279 | (pass-if "0" |
280 | (exact? 0)) | |
de142bea | 281 | |
21e39e8f DH |
282 | (pass-if "fixnum-max" |
283 | (exact? fixnum-max)) | |
de142bea | 284 | |
21e39e8f DH |
285 | (pass-if "fixnum-max + 1" |
286 | (exact? (+ fixnum-max 1))) | |
de142bea | 287 | |
21e39e8f DH |
288 | (pass-if "fixnum-min" |
289 | (exact? fixnum-min)) | |
de142bea | 290 | |
21e39e8f DH |
291 | (pass-if "fixnum-min - 1" |
292 | (exact? (- fixnum-min 1)))) | |
293 | ||
294 | (with-test-prefix "reals" | |
295 | ||
296 | ;; (FIXME: need better examples.) | |
297 | ||
298 | (pass-if "sqrt (fixnum-max^2 - 1)" | |
299 | (eq? #f (exact? (sqrt (- (expt fixnum-max 2) 1))))) | |
300 | ||
301 | (pass-if "sqrt ((fixnum-max+1)^2 - 1)" | |
41df63cf MW |
302 | (eq? #f (exact? (sqrt (- (expt (+ fixnum-max 1) 2) 1))))) |
303 | ||
304 | (pass-if (not (exact? +inf.0))) | |
305 | (pass-if (not (exact? -inf.0))) | |
306 | (pass-if (not (exact? +nan.0))))) | |
de142bea | 307 | |
8ab3d8a0 KR |
308 | ;;; |
309 | ;;; exp | |
310 | ;;; | |
311 | ||
312 | (with-test-prefix "exp" | |
2519490c | 313 | (pass-if (documented? exp)) |
8ab3d8a0 KR |
314 | |
315 | (pass-if-exception "no args" exception:wrong-num-args | |
316 | (exp)) | |
317 | (pass-if-exception "two args" exception:wrong-num-args | |
318 | (exp 123 456)) | |
319 | ||
320 | (pass-if (eqv? 0.0 (exp -inf.0))) | |
321 | (pass-if (eqv-loosely? 1.0 (exp 0))) | |
322 | (pass-if (eqv-loosely? 1.0 (exp 0.0))) | |
323 | (pass-if (eqv-loosely? const-e (exp 1.0))) | |
324 | (pass-if (eqv-loosely? const-e^2 (exp 2.0))) | |
325 | (pass-if (eqv-loosely? const-1/e (exp -1))) | |
326 | ||
327 | (pass-if "exp(pi*i) = -1" | |
328 | (eqv-loosely? -1.0 (exp 0+3.14159i))) | |
329 | (pass-if "exp(-pi*i) = -1" | |
330 | (eqv-loosely? -1.0 (exp 0-3.14159i))) | |
331 | (pass-if "exp(2*pi*i) = +1" | |
332 | (eqv-loosely? 1.0 (exp 0+6.28318i))) | |
333 | ||
334 | (pass-if "exp(2-pi*i) = -e^2" | |
335 | (eqv-loosely? (- const-e^2) (exp 2.0-3.14159i)))) | |
336 | ||
de142bea DH |
337 | ;;; |
338 | ;;; odd? | |
339 | ;;; | |
340 | ||
7c24e528 RB |
341 | (with-test-prefix "odd?" |
342 | (pass-if (documented? odd?)) | |
343 | (pass-if (odd? 1)) | |
344 | (pass-if (odd? -1)) | |
4d332f19 DH |
345 | (pass-if (not (odd? 0))) |
346 | (pass-if (not (odd? 2))) | |
347 | (pass-if (not (odd? -2))) | |
7c24e528 | 348 | (pass-if (odd? (+ (* 2 fixnum-max) 1))) |
4d332f19 | 349 | (pass-if (not (odd? (* 2 fixnum-max)))) |
7c24e528 | 350 | (pass-if (odd? (- (* 2 fixnum-min) 1))) |
4d332f19 | 351 | (pass-if (not (odd? (* 2 fixnum-min))))) |
de142bea DH |
352 | |
353 | ;;; | |
354 | ;;; even? | |
355 | ;;; | |
356 | ||
7c24e528 RB |
357 | (with-test-prefix "even?" |
358 | (pass-if (documented? even?)) | |
359 | (pass-if (even? 2)) | |
360 | (pass-if (even? -2)) | |
361 | (pass-if (even? 0)) | |
4d332f19 DH |
362 | (pass-if (not (even? 1))) |
363 | (pass-if (not (even? -1))) | |
364 | (pass-if (not (even? (+ (* 2 fixnum-max) 1)))) | |
7c24e528 | 365 | (pass-if (even? (* 2 fixnum-max))) |
4d332f19 | 366 | (pass-if (not (even? (- (* 2 fixnum-min) 1)))) |
7c24e528 | 367 | (pass-if (even? (* 2 fixnum-min)))) |
de142bea | 368 | |
7112615f MW |
369 | ;;; |
370 | ;;; finite? | |
371 | ;;; | |
372 | ||
373 | (with-test-prefix "finite?" | |
374 | (pass-if (documented? finite?)) | |
375 | (pass-if (not (finite? (inf)))) | |
376 | (pass-if (not (finite? +inf.0))) | |
377 | (pass-if (not (finite? -inf.0))) | |
10391e06 | 378 | (pass-if-exception |
c9cf90d4 | 379 | "complex numbers not in domain of finite?" |
10391e06 AW |
380 | exception:wrong-type-arg |
381 | (finite? +inf.0+1i)) | |
382 | (pass-if-exception | |
c9cf90d4 | 383 | "complex numbers not in domain of finite? (2)" |
10391e06 AW |
384 | exception:wrong-type-arg |
385 | (finite? +1+inf.0i)) | |
386 | (pass-if-exception | |
c9cf90d4 | 387 | "complex numbers not in domain of finite? (3)" |
10391e06 AW |
388 | exception:wrong-type-arg |
389 | (finite? +1+1i)) | |
390 | (pass-if (finite? 3+0i)) | |
7112615f MW |
391 | (pass-if (not (finite? (nan)))) |
392 | (pass-if (not (finite? +nan.0))) | |
7112615f MW |
393 | (pass-if (finite? 0)) |
394 | (pass-if (finite? 0.0)) | |
395 | (pass-if (finite? -0.0)) | |
396 | (pass-if (finite? 42.0)) | |
397 | (pass-if (finite? 1/2)) | |
7112615f MW |
398 | (pass-if (finite? (+ fixnum-max 1))) |
399 | (pass-if (finite? (- fixnum-min 1)))) | |
400 | ||
de142bea | 401 | ;;; |
7c24e528 RB |
402 | ;;; inf? and inf |
403 | ;;; | |
404 | ||
405 | (with-test-prefix "inf?" | |
406 | (pass-if (documented? inf?)) | |
407 | (pass-if (inf? (inf))) | |
408 | ;; FIXME: what are the expected behaviors? | |
409 | ;; (pass-if (inf? (/ 1.0 0.0)) | |
410 | ;; (pass-if (inf? (/ 1 0.0)) | |
10391e06 | 411 | (pass-if-exception |
c9cf90d4 | 412 | "complex numbers not in domain of inf?" |
10391e06 AW |
413 | exception:wrong-type-arg |
414 | (inf? +1+inf.0i)) | |
415 | (pass-if (inf? +inf.0+0i)) | |
4d332f19 DH |
416 | (pass-if (not (inf? 0))) |
417 | (pass-if (not (inf? 42.0))) | |
418 | (pass-if (not (inf? (+ fixnum-max 1)))) | |
419 | (pass-if (not (inf? (- fixnum-min 1))))) | |
7c24e528 RB |
420 | |
421 | ;;; | |
422 | ;;; nan? and nan | |
de142bea DH |
423 | ;;; |
424 | ||
7c24e528 RB |
425 | (with-test-prefix "nan?" |
426 | (pass-if (documented? nan?)) | |
427 | (pass-if (nan? (nan))) | |
428 | ;; FIXME: other ways we should be able to generate NaN? | |
4d332f19 DH |
429 | (pass-if (not (nan? 0))) |
430 | (pass-if (not (nan? 42.0))) | |
431 | (pass-if (not (nan? (+ fixnum-max 1)))) | |
432 | (pass-if (not (nan? (- fixnum-min 1))))) | |
de142bea | 433 | |
7c24e528 RB |
434 | ;;; |
435 | ;;; abs | |
436 | ;;; | |
437 | ||
438 | (with-test-prefix "abs" | |
439 | (pass-if (documented? abs)) | |
9b9ef10c MW |
440 | (pass-if (eqv? 0 (abs 0))) |
441 | (pass-if (eqv? 1 (abs 1))) | |
442 | (pass-if (eqv? 1 (abs -1))) | |
443 | ||
444 | (with-test-prefix "double-negation of fixnum-min" | |
445 | (pass-if (eqv? fixnum-min (- (abs fixnum-min))))) | |
446 | ||
447 | (pass-if (eqv? (+ fixnum-max 1) (abs (+ fixnum-max 1)))) | |
448 | (pass-if (eqv? (+ (- fixnum-min) 1) (abs (- fixnum-min 1)))) | |
449 | ||
450 | (pass-if (eqv? 0.0 (abs 0.0))) | |
451 | (pass-if (eqv? 0.0 (abs -0.0))) | |
452 | (pass-if (eqv? 1.0 (abs 1.0))) | |
453 | (pass-if (eqv? 1.0 (abs -1.0))) | |
454 | (pass-if (real-nan? (abs +nan.0))) | |
455 | (pass-if (eqv? +inf.0 (abs +inf.0))) | |
456 | (pass-if (eqv? +inf.0 (abs -inf.0)))) | |
76903a31 | 457 | |
de142bea DH |
458 | ;;; |
459 | ;;; quotient | |
460 | ;;; | |
461 | ||
462 | (with-test-prefix "quotient" | |
2519490c | 463 | (pass-if (documented? quotient)) |
de142bea | 464 | |
de142bea DH |
465 | (with-test-prefix "0 / n" |
466 | ||
467 | (pass-if "n = 1" | |
468 | (eqv? 0 (quotient 0 1))) | |
469 | ||
470 | (pass-if "n = -1" | |
471 | (eqv? 0 (quotient 0 -1))) | |
472 | ||
21e39e8f DH |
473 | (pass-if "n = 2" |
474 | (eqv? 0 (quotient 0 2))) | |
475 | ||
476 | (pass-if "n = fixnum-max" | |
477 | (eqv? 0 (quotient 0 fixnum-max))) | |
478 | ||
479 | (pass-if "n = fixnum-max + 1" | |
480 | (eqv? 0 (quotient 0 (+ fixnum-max 1)))) | |
481 | ||
482 | (pass-if "n = fixnum-min" | |
483 | (eqv? 0 (quotient 0 fixnum-min))) | |
484 | ||
485 | (pass-if "n = fixnum-min - 1" | |
486 | (eqv? 0 (quotient 0 (- fixnum-min 1))))) | |
de142bea | 487 | |
21e39e8f | 488 | (with-test-prefix "1 / n" |
de142bea DH |
489 | |
490 | (pass-if "n = 1" | |
491 | (eqv? 1 (quotient 1 1))) | |
492 | ||
493 | (pass-if "n = -1" | |
21e39e8f DH |
494 | (eqv? -1 (quotient 1 -1))) |
495 | ||
496 | (pass-if "n = 2" | |
497 | (eqv? 0 (quotient 1 2))) | |
de142bea | 498 | |
21e39e8f DH |
499 | (pass-if "n = fixnum-max" |
500 | (eqv? 0 (quotient 1 fixnum-max))) | |
de142bea | 501 | |
21e39e8f DH |
502 | (pass-if "n = fixnum-max + 1" |
503 | (eqv? 0 (quotient 1 (+ fixnum-max 1)))) | |
de142bea | 504 | |
21e39e8f DH |
505 | (pass-if "n = fixnum-min" |
506 | (eqv? 0 (quotient 1 fixnum-min))) | |
507 | ||
508 | (pass-if "n = fixnum-min - 1" | |
509 | (eqv? 0 (quotient 1 (- fixnum-min 1))))) | |
510 | ||
511 | (with-test-prefix "-1 / n" | |
de142bea DH |
512 | |
513 | (pass-if "n = 1" | |
21e39e8f | 514 | (eqv? -1 (quotient -1 1))) |
de142bea DH |
515 | |
516 | (pass-if "n = -1" | |
517 | (eqv? 1 (quotient -1 -1))) | |
518 | ||
21e39e8f DH |
519 | (pass-if "n = 2" |
520 | (eqv? 0 (quotient -1 2))) | |
521 | ||
522 | (pass-if "n = fixnum-max" | |
523 | (eqv? 0 (quotient -1 fixnum-max))) | |
524 | ||
525 | (pass-if "n = fixnum-max + 1" | |
526 | (eqv? 0 (quotient -1 (+ fixnum-max 1)))) | |
527 | ||
528 | (pass-if "n = fixnum-min" | |
529 | (eqv? 0 (quotient -1 fixnum-min))) | |
530 | ||
531 | (pass-if "n = fixnum-min - 1" | |
532 | (eqv? 0 (quotient -1 (- fixnum-min 1))))) | |
533 | ||
534 | (with-test-prefix "fixnum-max / n" | |
535 | ||
536 | (pass-if "n = 1" | |
537 | (eqv? fixnum-max (quotient fixnum-max 1))) | |
538 | ||
539 | (pass-if "n = -1" | |
540 | (eqv? (- fixnum-max) (quotient fixnum-max -1))) | |
541 | ||
542 | (pass-if "n = 2" | |
543 | (eqv? fixnum-max (+ (* (quotient fixnum-max 2) 2) 1))) | |
544 | ||
545 | (pass-if "n = fixnum-max" | |
546 | (eqv? 1 (quotient fixnum-max fixnum-max))) | |
547 | ||
548 | (pass-if "n = fixnum-max + 1" | |
549 | (eqv? 0 (quotient fixnum-max (+ fixnum-max 1)))) | |
550 | ||
551 | (pass-if "n = fixnum-min" | |
552 | (eqv? 0 (quotient fixnum-max fixnum-min))) | |
553 | ||
554 | (pass-if "n = fixnum-min - 1" | |
555 | (eqv? 0 (quotient fixnum-max (- fixnum-min 1))))) | |
556 | ||
557 | (with-test-prefix "(fixnum-max + 1) / n" | |
558 | ||
559 | (pass-if "n = 1" | |
560 | (eqv? (+ fixnum-max 1) (quotient (+ fixnum-max 1) 1))) | |
561 | ||
562 | (pass-if "n = -1" | |
563 | (eqv? (- (+ fixnum-max 1)) (quotient (+ fixnum-max 1) -1))) | |
564 | ||
565 | (pass-if "n = 2" | |
566 | (eqv? (+ fixnum-max 1) (* (quotient (+ fixnum-max 1) 2) 2))) | |
567 | ||
568 | (pass-if "n = fixnum-max" | |
569 | (eqv? 1 (quotient (+ fixnum-max 1) fixnum-max))) | |
570 | ||
571 | (pass-if "n = fixnum-max + 1" | |
572 | (eqv? 1 (quotient (+ fixnum-max 1) (+ fixnum-max 1)))) | |
573 | ||
574 | (pass-if "n = fixnum-min" | |
575 | (eqv? -1 (quotient (+ fixnum-max 1) fixnum-min))) | |
576 | ||
577 | (pass-if "n = fixnum-min - 1" | |
578 | (eqv? 0 (quotient (+ fixnum-max 1) (- fixnum-min 1))))) | |
579 | ||
580 | (with-test-prefix "fixnum-min / n" | |
581 | ||
582 | (pass-if "n = 1" | |
583 | (eqv? fixnum-min (quotient fixnum-min 1))) | |
584 | ||
585 | (pass-if "n = -1" | |
586 | (eqv? (- fixnum-min) (quotient fixnum-min -1))) | |
587 | ||
588 | (pass-if "n = 2" | |
589 | (eqv? fixnum-min (* (quotient fixnum-min 2) 2))) | |
590 | ||
591 | (pass-if "n = fixnum-max" | |
592 | (eqv? -1 (quotient fixnum-min fixnum-max))) | |
593 | ||
594 | (pass-if "n = fixnum-max + 1" | |
595 | (eqv? -1 (quotient fixnum-min (+ fixnum-max 1)))) | |
596 | ||
597 | (pass-if "n = fixnum-min" | |
598 | (eqv? 1 (quotient fixnum-min fixnum-min))) | |
599 | ||
600 | (pass-if "n = fixnum-min - 1" | |
ad22fe7c KR |
601 | (eqv? 0 (quotient fixnum-min (- fixnum-min 1)))) |
602 | ||
603 | (pass-if "n = - fixnum-min - 1" | |
604 | (eqv? -1 (quotient fixnum-min (1- (- fixnum-min))))) | |
605 | ||
606 | ;; special case, normally inum/big is zero | |
607 | (pass-if "n = - fixnum-min" | |
608 | (eqv? -1 (quotient fixnum-min (- fixnum-min)))) | |
609 | ||
610 | (pass-if "n = - fixnum-min + 1" | |
611 | (eqv? 0 (quotient fixnum-min (1+ (- fixnum-min)))))) | |
21e39e8f DH |
612 | |
613 | (with-test-prefix "(fixnum-min - 1) / n" | |
614 | ||
615 | (pass-if "n = 1" | |
616 | (eqv? (- fixnum-min 1) (quotient (- fixnum-min 1) 1))) | |
617 | ||
618 | (pass-if "n = -1" | |
619 | (eqv? (- (- fixnum-min 1)) (quotient (- fixnum-min 1) -1))) | |
620 | ||
621 | (pass-if "n = 2" | |
622 | (eqv? fixnum-min (* (quotient (- fixnum-min 1) 2) 2))) | |
623 | ||
624 | (pass-if "n = fixnum-max" | |
625 | (eqv? -1 (quotient (- fixnum-min 1) fixnum-max))) | |
626 | ||
627 | (pass-if "n = fixnum-max + 1" | |
628 | (eqv? -1 (quotient (- fixnum-min 1) (+ fixnum-max 1)))) | |
629 | ||
630 | (pass-if "n = fixnum-min" | |
631 | (eqv? 1 (quotient (- fixnum-min 1) fixnum-min))) | |
632 | ||
633 | (pass-if "n = fixnum-min - 1" | |
634 | (eqv? 1 (quotient (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
635 | |
636 | ;; Positive dividend and divisor | |
637 | ||
638 | (pass-if "35 / 7" | |
639 | (eqv? 5 (quotient 35 7))) | |
640 | ||
641 | ;; Negative dividend, positive divisor | |
642 | ||
643 | (pass-if "-35 / 7" | |
644 | (eqv? -5 (quotient -35 7))) | |
645 | ||
646 | ;; Positive dividend, negative divisor | |
647 | ||
648 | (pass-if "35 / -7" | |
649 | (eqv? -5 (quotient 35 -7))) | |
650 | ||
651 | ;; Negative dividend and divisor | |
652 | ||
653 | (pass-if "-35 / -7" | |
654 | (eqv? 5 (quotient -35 -7))) | |
655 | ||
656 | ;; Are numerical overflows detected correctly? | |
657 | ||
80074d77 DH |
658 | (with-test-prefix "division by zero" |
659 | ||
660 | (pass-if-exception "(quotient 1 0)" | |
661 | exception:numerical-overflow | |
662 | (quotient 1 0)) | |
663 | ||
664 | (pass-if-exception "(quotient bignum 0)" | |
665 | exception:numerical-overflow | |
666 | (quotient (+ fixnum-max 1) 0))) | |
667 | ||
de142bea DH |
668 | ;; Are wrong type arguments detected correctly? |
669 | ||
670 | ) | |
671 | ||
672 | ;;; | |
673 | ;;; remainder | |
674 | ;;; | |
675 | ||
676 | (with-test-prefix "remainder" | |
2519490c | 677 | (pass-if (documented? remainder)) |
de142bea | 678 | |
de142bea DH |
679 | (with-test-prefix "0 / n" |
680 | ||
681 | (pass-if "n = 1" | |
682 | (eqv? 0 (remainder 0 1))) | |
683 | ||
684 | (pass-if "n = -1" | |
685 | (eqv? 0 (remainder 0 -1))) | |
686 | ||
21e39e8f DH |
687 | (pass-if "n = fixnum-max" |
688 | (eqv? 0 (remainder 0 fixnum-max))) | |
689 | ||
690 | (pass-if "n = fixnum-max + 1" | |
691 | (eqv? 0 (remainder 0 (+ fixnum-max 1)))) | |
692 | ||
693 | (pass-if "n = fixnum-min" | |
694 | (eqv? 0 (remainder 0 fixnum-min))) | |
de142bea | 695 | |
21e39e8f DH |
696 | (pass-if "n = fixnum-min - 1" |
697 | (eqv? 0 (remainder 0 (- fixnum-min 1))))) | |
de142bea | 698 | |
21e39e8f | 699 | (with-test-prefix "1 / n" |
de142bea DH |
700 | |
701 | (pass-if "n = 1" | |
702 | (eqv? 0 (remainder 1 1))) | |
703 | ||
704 | (pass-if "n = -1" | |
21e39e8f DH |
705 | (eqv? 0 (remainder 1 -1))) |
706 | ||
707 | (pass-if "n = fixnum-max" | |
708 | (eqv? 1 (remainder 1 fixnum-max))) | |
de142bea | 709 | |
21e39e8f DH |
710 | (pass-if "n = fixnum-max + 1" |
711 | (eqv? 1 (remainder 1 (+ fixnum-max 1)))) | |
de142bea | 712 | |
21e39e8f DH |
713 | (pass-if "n = fixnum-min" |
714 | (eqv? 1 (remainder 1 fixnum-min))) | |
de142bea | 715 | |
21e39e8f DH |
716 | (pass-if "n = fixnum-min - 1" |
717 | (eqv? 1 (remainder 1 (- fixnum-min 1))))) | |
718 | ||
719 | (with-test-prefix "-1 / n" | |
de142bea DH |
720 | |
721 | (pass-if "n = 1" | |
21e39e8f | 722 | (eqv? 0 (remainder -1 1))) |
de142bea DH |
723 | |
724 | (pass-if "n = -1" | |
725 | (eqv? 0 (remainder -1 -1))) | |
726 | ||
21e39e8f DH |
727 | (pass-if "n = fixnum-max" |
728 | (eqv? -1 (remainder -1 fixnum-max))) | |
729 | ||
730 | (pass-if "n = fixnum-max + 1" | |
731 | (eqv? -1 (remainder -1 (+ fixnum-max 1)))) | |
732 | ||
733 | (pass-if "n = fixnum-min" | |
734 | (eqv? -1 (remainder -1 fixnum-min))) | |
735 | ||
736 | (pass-if "n = fixnum-min - 1" | |
737 | (eqv? -1 (remainder -1 (- fixnum-min 1))))) | |
738 | ||
739 | (with-test-prefix "fixnum-max / n" | |
740 | ||
741 | (pass-if "n = 1" | |
742 | (eqv? 0 (remainder fixnum-max 1))) | |
743 | ||
744 | (pass-if "n = -1" | |
745 | (eqv? 0 (remainder fixnum-max -1))) | |
746 | ||
747 | (pass-if "n = fixnum-max" | |
748 | (eqv? 0 (remainder fixnum-max fixnum-max))) | |
749 | ||
750 | (pass-if "n = fixnum-max + 1" | |
751 | (eqv? fixnum-max (remainder fixnum-max (+ fixnum-max 1)))) | |
752 | ||
753 | (pass-if "n = fixnum-min" | |
754 | (eqv? fixnum-max (remainder fixnum-max fixnum-min))) | |
755 | ||
756 | (pass-if "n = fixnum-min - 1" | |
757 | (eqv? fixnum-max (remainder fixnum-max (- fixnum-min 1))))) | |
758 | ||
759 | (with-test-prefix "(fixnum-max + 1) / n" | |
760 | ||
761 | (pass-if "n = 1" | |
762 | (eqv? 0 (remainder (+ fixnum-max 1) 1))) | |
763 | ||
764 | (pass-if "n = -1" | |
765 | (eqv? 0 (remainder (+ fixnum-max 1) -1))) | |
766 | ||
767 | (pass-if "n = fixnum-max" | |
768 | (eqv? 1 (remainder (+ fixnum-max 1) fixnum-max))) | |
769 | ||
770 | (pass-if "n = fixnum-max + 1" | |
771 | (eqv? 0 (remainder (+ fixnum-max 1) (+ fixnum-max 1)))) | |
772 | ||
773 | (pass-if "n = fixnum-min" | |
774 | (eqv? 0 (remainder (+ fixnum-max 1) fixnum-min))) | |
775 | ||
776 | (pass-if "n = fixnum-min - 1" | |
777 | (eqv? (+ fixnum-max 1) (remainder (+ fixnum-max 1) (- fixnum-min 1))))) | |
778 | ||
779 | (with-test-prefix "fixnum-min / n" | |
780 | ||
781 | (pass-if "n = 1" | |
782 | (eqv? 0 (remainder fixnum-min 1))) | |
783 | ||
784 | (pass-if "n = -1" | |
785 | (eqv? 0 (remainder fixnum-min -1))) | |
786 | ||
787 | (pass-if "n = fixnum-max" | |
788 | (eqv? -1 (remainder fixnum-min fixnum-max))) | |
789 | ||
790 | (pass-if "n = fixnum-max + 1" | |
791 | (eqv? 0 (remainder fixnum-min (+ fixnum-max 1)))) | |
792 | ||
793 | (pass-if "n = fixnum-min" | |
794 | (eqv? 0 (remainder fixnum-min fixnum-min))) | |
795 | ||
796 | (pass-if "n = fixnum-min - 1" | |
ad22fe7c KR |
797 | (eqv? fixnum-min (remainder fixnum-min (- fixnum-min 1)))) |
798 | ||
799 | (pass-if "n = - fixnum-min - 1" | |
800 | (eqv? -1 (remainder fixnum-min (1- (- fixnum-min))))) | |
801 | ||
802 | ;; special case, normally inum%big is the inum | |
803 | (pass-if "n = - fixnum-min" | |
804 | (eqv? 0 (remainder fixnum-min (- fixnum-min)))) | |
805 | ||
806 | (pass-if "n = - fixnum-min + 1" | |
807 | (eqv? fixnum-min (remainder fixnum-min (1+ (- fixnum-min)))))) | |
21e39e8f DH |
808 | |
809 | (with-test-prefix "(fixnum-min - 1) / n" | |
810 | ||
811 | (pass-if "n = 1" | |
812 | (eqv? 0 (remainder (- fixnum-min 1) 1))) | |
813 | ||
814 | (pass-if "n = -1" | |
815 | (eqv? 0 (remainder (- fixnum-min 1) -1))) | |
816 | ||
817 | (pass-if "n = fixnum-max" | |
818 | (eqv? -2 (remainder (- fixnum-min 1) fixnum-max))) | |
819 | ||
820 | (pass-if "n = fixnum-max + 1" | |
821 | (eqv? -1 (remainder (- fixnum-min 1) (+ fixnum-max 1)))) | |
822 | ||
823 | (pass-if "n = fixnum-min" | |
824 | (eqv? -1 (remainder (- fixnum-min 1) fixnum-min))) | |
825 | ||
826 | (pass-if "n = fixnum-min - 1" | |
827 | (eqv? 0 (remainder (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
828 | |
829 | ;; Positive dividend and divisor | |
830 | ||
831 | (pass-if "35 / 7" | |
832 | (eqv? 0 (remainder 35 7))) | |
833 | ||
834 | ;; Negative dividend, positive divisor | |
835 | ||
836 | (pass-if "-35 / 7" | |
837 | (eqv? 0 (remainder -35 7))) | |
838 | ||
839 | ;; Positive dividend, negative divisor | |
840 | ||
841 | (pass-if "35 / -7" | |
842 | (eqv? 0 (remainder 35 -7))) | |
843 | ||
844 | ;; Negative dividend and divisor | |
845 | ||
846 | (pass-if "-35 / -7" | |
847 | (eqv? 0 (remainder -35 -7))) | |
848 | ||
849 | ;; Are numerical overflows detected correctly? | |
850 | ||
80074d77 DH |
851 | (with-test-prefix "division by zero" |
852 | ||
853 | (pass-if-exception "(remainder 1 0)" | |
854 | exception:numerical-overflow | |
855 | (remainder 1 0)) | |
856 | ||
857 | (pass-if-exception "(remainder bignum 0)" | |
858 | exception:numerical-overflow | |
859 | (remainder (+ fixnum-max 1) 0))) | |
860 | ||
de142bea DH |
861 | ;; Are wrong type arguments detected correctly? |
862 | ||
863 | ) | |
864 | ||
865 | ;;; | |
866 | ;;; modulo | |
867 | ;;; | |
868 | ||
869 | (with-test-prefix "modulo" | |
2519490c | 870 | (pass-if (documented? modulo)) |
de142bea | 871 | |
de142bea DH |
872 | (with-test-prefix "0 % n" |
873 | ||
874 | (pass-if "n = 1" | |
875 | (eqv? 0 (modulo 0 1))) | |
876 | ||
877 | (pass-if "n = -1" | |
878 | (eqv? 0 (modulo 0 -1))) | |
879 | ||
21e39e8f DH |
880 | (pass-if "n = fixnum-max" |
881 | (eqv? 0 (modulo 0 fixnum-max))) | |
882 | ||
883 | (pass-if "n = fixnum-max + 1" | |
884 | (eqv? 0 (modulo 0 (+ fixnum-max 1)))) | |
de142bea | 885 | |
21e39e8f DH |
886 | (pass-if "n = fixnum-min" |
887 | (eqv? 0 (modulo 0 fixnum-min))) | |
de142bea | 888 | |
21e39e8f DH |
889 | (pass-if "n = fixnum-min - 1" |
890 | (eqv? 0 (modulo 0 (- fixnum-min 1))))) | |
891 | ||
892 | (with-test-prefix "1 % n" | |
de142bea DH |
893 | |
894 | (pass-if "n = 1" | |
895 | (eqv? 0 (modulo 1 1))) | |
896 | ||
897 | (pass-if "n = -1" | |
21e39e8f | 898 | (eqv? 0 (modulo 1 -1))) |
de142bea | 899 | |
21e39e8f DH |
900 | (pass-if "n = fixnum-max" |
901 | (eqv? 1 (modulo 1 fixnum-max))) | |
de142bea | 902 | |
21e39e8f DH |
903 | (pass-if "n = fixnum-max + 1" |
904 | (eqv? 1 (modulo 1 (+ fixnum-max 1)))) | |
de142bea | 905 | |
21e39e8f DH |
906 | (pass-if "n = fixnum-min" |
907 | (eqv? (+ fixnum-min 1) (modulo 1 fixnum-min))) | |
908 | ||
909 | (pass-if "n = fixnum-min - 1" | |
910 | (eqv? fixnum-min (modulo 1 (- fixnum-min 1))))) | |
911 | ||
912 | (with-test-prefix "-1 % n" | |
de142bea DH |
913 | |
914 | (pass-if "n = 1" | |
21e39e8f | 915 | (eqv? 0 (modulo -1 1))) |
de142bea DH |
916 | |
917 | (pass-if "n = -1" | |
918 | (eqv? 0 (modulo -1 -1))) | |
919 | ||
21e39e8f DH |
920 | (pass-if "n = fixnum-max" |
921 | (eqv? (- fixnum-max 1) (modulo -1 fixnum-max))) | |
922 | ||
923 | (pass-if "n = fixnum-max + 1" | |
924 | (eqv? fixnum-max (modulo -1 (+ fixnum-max 1)))) | |
925 | ||
926 | (pass-if "n = fixnum-min" | |
927 | (eqv? -1 (modulo -1 fixnum-min))) | |
928 | ||
929 | (pass-if "n = fixnum-min - 1" | |
930 | (eqv? -1 (modulo -1 (- fixnum-min 1))))) | |
931 | ||
932 | (with-test-prefix "fixnum-max % n" | |
933 | ||
934 | (pass-if "n = 1" | |
935 | (eqv? 0 (modulo fixnum-max 1))) | |
936 | ||
937 | (pass-if "n = -1" | |
938 | (eqv? 0 (modulo fixnum-max -1))) | |
939 | ||
940 | (pass-if "n = fixnum-max" | |
941 | (eqv? 0 (modulo fixnum-max fixnum-max))) | |
942 | ||
943 | (pass-if "n = fixnum-max + 1" | |
944 | (eqv? fixnum-max (modulo fixnum-max (+ fixnum-max 1)))) | |
945 | ||
946 | (pass-if "n = fixnum-min" | |
947 | (eqv? -1 (modulo fixnum-max fixnum-min))) | |
948 | ||
949 | (pass-if "n = fixnum-min - 1" | |
950 | (eqv? -2 (modulo fixnum-max (- fixnum-min 1))))) | |
951 | ||
952 | (with-test-prefix "(fixnum-max + 1) % n" | |
953 | ||
954 | (pass-if "n = 1" | |
955 | (eqv? 0 (modulo (+ fixnum-max 1) 1))) | |
956 | ||
957 | (pass-if "n = -1" | |
958 | (eqv? 0 (modulo (+ fixnum-max 1) -1))) | |
959 | ||
960 | (pass-if "n = fixnum-max" | |
961 | (eqv? 1 (modulo (+ fixnum-max 1) fixnum-max))) | |
962 | ||
963 | (pass-if "n = fixnum-max + 1" | |
964 | (eqv? 0 (modulo (+ fixnum-max 1) (+ fixnum-max 1)))) | |
965 | ||
966 | (pass-if "n = fixnum-min" | |
967 | (eqv? 0 (modulo (+ fixnum-max 1) fixnum-min))) | |
968 | ||
969 | (pass-if "n = fixnum-min - 1" | |
970 | (eqv? -1 (modulo (+ fixnum-max 1) (- fixnum-min 1))))) | |
971 | ||
972 | (with-test-prefix "fixnum-min % n" | |
973 | ||
974 | (pass-if "n = 1" | |
975 | (eqv? 0 (modulo fixnum-min 1))) | |
976 | ||
977 | (pass-if "n = -1" | |
978 | (eqv? 0 (modulo fixnum-min -1))) | |
979 | ||
980 | (pass-if "n = fixnum-max" | |
981 | (eqv? (- fixnum-max 1) (modulo fixnum-min fixnum-max))) | |
982 | ||
983 | (pass-if "n = fixnum-max + 1" | |
984 | (eqv? 0 (modulo fixnum-min (+ fixnum-max 1)))) | |
985 | ||
986 | (pass-if "n = fixnum-min" | |
987 | (eqv? 0 (modulo fixnum-min fixnum-min))) | |
988 | ||
989 | (pass-if "n = fixnum-min - 1" | |
990 | (eqv? fixnum-min (modulo fixnum-min (- fixnum-min 1))))) | |
991 | ||
992 | (with-test-prefix "(fixnum-min - 1) % n" | |
993 | ||
994 | (pass-if "n = 1" | |
995 | (eqv? 0 (modulo (- fixnum-min 1) 1))) | |
996 | ||
997 | (pass-if "n = -1" | |
998 | (eqv? 0 (modulo (- fixnum-min 1) -1))) | |
999 | ||
1000 | (pass-if "n = fixnum-max" | |
1001 | (eqv? (- fixnum-max 2) (modulo (- fixnum-min 1) fixnum-max))) | |
1002 | ||
1003 | (pass-if "n = fixnum-max + 1" | |
1004 | (eqv? fixnum-max (modulo (- fixnum-min 1) (+ fixnum-max 1)))) | |
1005 | ||
1006 | (pass-if "n = fixnum-min" | |
1007 | (eqv? -1 (modulo (- fixnum-min 1) fixnum-min))) | |
1008 | ||
1009 | (pass-if "n = fixnum-min - 1" | |
1010 | (eqv? 0 (modulo (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
1011 | |
1012 | ;; Positive dividend and divisor | |
1013 | ||
1014 | (pass-if "13 % 4" | |
1015 | (eqv? 1 (modulo 13 4))) | |
1016 | ||
1017 | (pass-if "2177452800 % 86400" | |
1018 | (eqv? 0 (modulo 2177452800 86400))) | |
1019 | ||
1020 | ;; Negative dividend, positive divisor | |
1021 | ||
1022 | (pass-if "-13 % 4" | |
1023 | (eqv? 3 (modulo -13 4))) | |
1024 | ||
1025 | (pass-if "-2177452800 % 86400" | |
1026 | (eqv? 0 (modulo -2177452800 86400))) | |
1027 | ||
1028 | ;; Positive dividend, negative divisor | |
1029 | ||
1030 | (pass-if "13 % -4" | |
1031 | (eqv? -3 (modulo 13 -4))) | |
1032 | ||
1033 | (pass-if "2177452800 % -86400" | |
1034 | (eqv? 0 (modulo 2177452800 -86400))) | |
1035 | ||
1036 | ;; Negative dividend and divisor | |
1037 | ||
1038 | (pass-if "-13 % -4" | |
1039 | (eqv? -1 (modulo -13 -4))) | |
1040 | ||
1041 | (pass-if "-2177452800 % -86400" | |
1042 | (eqv? 0 (modulo -2177452800 -86400))) | |
1043 | ||
1044 | ;; Are numerical overflows detected correctly? | |
1045 | ||
80074d77 DH |
1046 | (with-test-prefix "division by zero" |
1047 | ||
1048 | (pass-if-exception "(modulo 1 0)" | |
1049 | exception:numerical-overflow | |
1050 | (modulo 1 0)) | |
1051 | ||
1052 | (pass-if-exception "(modulo bignum 0)" | |
1053 | exception:numerical-overflow | |
1054 | (modulo (+ fixnum-max 1) 0))) | |
1055 | ||
de142bea DH |
1056 | ;; Are wrong type arguments detected correctly? |
1057 | ||
1058 | ) | |
1059 | ||
24360e11 KR |
1060 | ;;; |
1061 | ;;; modulo-expt | |
1062 | ;;; | |
1063 | ||
1064 | (with-test-prefix "modulo-expt" | |
1065 | (pass-if (= 1 (modulo-expt 17 23 47))) | |
1066 | ||
1067 | (pass-if (= 1 (modulo-expt 17 -23 47))) | |
1068 | ||
1069 | (pass-if (= 17 (modulo-expt 17 -22 47))) | |
1070 | ||
1071 | (pass-if (= 36 (modulo-expt 17 22 47))) | |
1072 | ||
1073 | (pass-if (= 183658794479969134816674175082294846241553725240 (modulo-expt 111122223333444455556666 111122223333444455556666 1153478690012629968439432872520758982731022934717))) | |
1074 | ||
1075 | (pass-if-exception | |
1076 | "Proper exception with 0 modulus" | |
18ee5de9 | 1077 | exception:numerical-overflow |
24360e11 KR |
1078 | (modulo-expt 17 23 0)) |
1079 | ||
1080 | (pass-if-exception | |
1081 | "Proper exception when result not invertible" | |
18ee5de9 | 1082 | exception:numerical-overflow |
24360e11 KR |
1083 | (modulo-expt 10 -1 48)) |
1084 | ||
1085 | (pass-if-exception | |
1086 | "Proper exception with wrong type argument" | |
18ee5de9 | 1087 | exception:wrong-type-arg |
24360e11 KR |
1088 | (modulo-expt "Sam" 23 10)) |
1089 | ||
1090 | (pass-if-exception | |
1091 | "Proper exception with wrong type argument" | |
18ee5de9 | 1092 | exception:wrong-type-arg |
24360e11 KR |
1093 | (modulo-expt 17 9.9 10)) |
1094 | ||
1095 | (pass-if-exception | |
1096 | "Proper exception with wrong type argument" | |
18ee5de9 | 1097 | exception:wrong-type-arg |
24360e11 KR |
1098 | (modulo-expt 17 23 'Ethel))) |
1099 | ||
ba46895c KR |
1100 | ;;; |
1101 | ;;; numerator | |
1102 | ;;; | |
1103 | ||
1104 | (with-test-prefix "numerator" | |
1105 | (pass-if "0" | |
1106 | (eqv? 0 (numerator 0))) | |
1107 | (pass-if "1" | |
1108 | (eqv? 1 (numerator 1))) | |
1109 | (pass-if "2" | |
1110 | (eqv? 2 (numerator 2))) | |
1111 | (pass-if "-1" | |
1112 | (eqv? -1 (numerator -1))) | |
1113 | (pass-if "-2" | |
1114 | (eqv? -2 (numerator -2))) | |
1115 | ||
1116 | (pass-if "0.0" | |
1117 | (eqv? 0.0 (numerator 0.0))) | |
1118 | (pass-if "1.0" | |
1119 | (eqv? 1.0 (numerator 1.0))) | |
1120 | (pass-if "2.0" | |
1121 | (eqv? 2.0 (numerator 2.0))) | |
1122 | (pass-if "-1.0" | |
1123 | (eqv? -1.0 (numerator -1.0))) | |
1124 | (pass-if "-2.0" | |
1125 | (eqv? -2.0 (numerator -2.0))) | |
1126 | ||
1127 | (pass-if "0.5" | |
1128 | (eqv? 1.0 (numerator 0.5))) | |
1129 | (pass-if "0.25" | |
1130 | (eqv? 1.0 (numerator 0.25))) | |
1131 | (pass-if "0.75" | |
1132 | (eqv? 3.0 (numerator 0.75)))) | |
1133 | ||
1134 | ;;; | |
1135 | ;;; denominator | |
1136 | ;;; | |
1137 | ||
1138 | (with-test-prefix "denominator" | |
1139 | (pass-if "0" | |
1140 | (eqv? 1 (denominator 0))) | |
1141 | (pass-if "1" | |
1142 | (eqv? 1 (denominator 1))) | |
1143 | (pass-if "2" | |
1144 | (eqv? 1 (denominator 2))) | |
1145 | (pass-if "-1" | |
1146 | (eqv? 1 (denominator -1))) | |
1147 | (pass-if "-2" | |
1148 | (eqv? 1 (denominator -2))) | |
1149 | ||
1150 | (pass-if "0.0" | |
1151 | (eqv? 1.0 (denominator 0.0))) | |
1152 | (pass-if "1.0" | |
1153 | (eqv? 1.0 (denominator 1.0))) | |
1154 | (pass-if "2.0" | |
1155 | (eqv? 1.0 (denominator 2.0))) | |
1156 | (pass-if "-1.0" | |
1157 | (eqv? 1.0 (denominator -1.0))) | |
1158 | (pass-if "-2.0" | |
1159 | (eqv? 1.0 (denominator -2.0))) | |
1160 | ||
1161 | (pass-if "0.5" | |
1162 | (eqv? 2.0 (denominator 0.5))) | |
1163 | (pass-if "0.25" | |
1164 | (eqv? 4.0 (denominator 0.25))) | |
1165 | (pass-if "0.75" | |
1166 | (eqv? 4.0 (denominator 0.75)))) | |
1167 | ||
de142bea DH |
1168 | ;;; |
1169 | ;;; gcd | |
1170 | ;;; | |
1171 | ||
1172 | (with-test-prefix "gcd" | |
1173 | ||
d389e966 | 1174 | (pass-if "documented?" |
cb18f2a8 | 1175 | (documented? gcd)) |
de142bea | 1176 | |
1dd79792 NJ |
1177 | (with-test-prefix "(n)" |
1178 | ||
1179 | (pass-if "n = -2" | |
1180 | (eqv? 2 (gcd -2)))) | |
1181 | ||
de142bea DH |
1182 | (with-test-prefix "(0 n)" |
1183 | ||
21e39e8f DH |
1184 | (pass-if "n = 0" |
1185 | (eqv? 0 (gcd 0 0))) | |
1186 | ||
de142bea DH |
1187 | (pass-if "n = 1" |
1188 | (eqv? 1 (gcd 0 1))) | |
1189 | ||
1190 | (pass-if "n = -1" | |
1191 | (eqv? 1 (gcd 0 -1))) | |
1192 | ||
21e39e8f DH |
1193 | (pass-if "n = fixnum-max" |
1194 | (eqv? fixnum-max (gcd 0 fixnum-max))) | |
de142bea | 1195 | |
21e39e8f DH |
1196 | (pass-if "n = fixnum-max + 1" |
1197 | (eqv? (+ fixnum-max 1) (gcd 0 (+ fixnum-max 1)))) | |
de142bea | 1198 | |
21e39e8f DH |
1199 | (pass-if "n = fixnum-min" |
1200 | (eqv? (- fixnum-min) (gcd 0 fixnum-min))) | |
de142bea | 1201 | |
21e39e8f DH |
1202 | (pass-if "n = fixnum-min - 1" |
1203 | (eqv? (- (- fixnum-min 1)) (gcd 0 (- fixnum-min 1))))) | |
1204 | ||
db386f80 KR |
1205 | (with-test-prefix "(n 0)" |
1206 | ||
1207 | (pass-if "n = 2^128 * fixnum-max" | |
1208 | (eqv? (ash fixnum-max 128) (gcd (ash fixnum-max 128) 0)))) | |
1209 | ||
21e39e8f DH |
1210 | (with-test-prefix "(1 n)" |
1211 | ||
1212 | (pass-if "n = 0" | |
de142bea DH |
1213 | (eqv? 1 (gcd 1 0))) |
1214 | ||
21e39e8f DH |
1215 | (pass-if "n = 1" |
1216 | (eqv? 1 (gcd 1 1))) | |
1217 | ||
de142bea | 1218 | (pass-if "n = -1" |
21e39e8f DH |
1219 | (eqv? 1 (gcd 1 -1))) |
1220 | ||
1221 | (pass-if "n = fixnum-max" | |
1222 | (eqv? 1 (gcd 1 fixnum-max))) | |
1223 | ||
1224 | (pass-if "n = fixnum-max + 1" | |
1225 | (eqv? 1 (gcd 1 (+ fixnum-max 1)))) | |
1226 | ||
1227 | (pass-if "n = fixnum-min" | |
1228 | (eqv? 1 (gcd 1 fixnum-min))) | |
1229 | ||
1230 | (pass-if "n = fixnum-min - 1" | |
1231 | (eqv? 1 (gcd 1 (- fixnum-min 1))))) | |
1232 | ||
1233 | (with-test-prefix "(-1 n)" | |
1234 | ||
1235 | (pass-if "n = 0" | |
de142bea DH |
1236 | (eqv? 1 (gcd -1 0))) |
1237 | ||
21e39e8f DH |
1238 | (pass-if "n = 1" |
1239 | (eqv? 1 (gcd -1 1))) | |
de142bea | 1240 | |
21e39e8f DH |
1241 | (pass-if "n = -1" |
1242 | (eqv? 1 (gcd -1 -1))) | |
de142bea | 1243 | |
21e39e8f DH |
1244 | (pass-if "n = fixnum-max" |
1245 | (eqv? 1 (gcd -1 fixnum-max))) | |
1246 | ||
1247 | (pass-if "n = fixnum-max + 1" | |
1248 | (eqv? 1 (gcd -1 (+ fixnum-max 1)))) | |
1249 | ||
1250 | (pass-if "n = fixnum-min" | |
1251 | (eqv? 1 (gcd -1 fixnum-min))) | |
1252 | ||
1253 | (pass-if "n = fixnum-min - 1" | |
1254 | (eqv? 1 (gcd -1 (- fixnum-min 1))))) | |
1255 | ||
1256 | (with-test-prefix "(fixnum-max n)" | |
1257 | ||
1258 | (pass-if "n = 0" | |
1259 | (eqv? fixnum-max (gcd fixnum-max 0))) | |
de142bea DH |
1260 | |
1261 | (pass-if "n = 1" | |
21e39e8f | 1262 | (eqv? 1 (gcd fixnum-max 1))) |
de142bea DH |
1263 | |
1264 | (pass-if "n = -1" | |
21e39e8f DH |
1265 | (eqv? 1 (gcd fixnum-max -1))) |
1266 | ||
1267 | (pass-if "n = fixnum-max" | |
1268 | (eqv? fixnum-max (gcd fixnum-max fixnum-max))) | |
de142bea | 1269 | |
21e39e8f DH |
1270 | (pass-if "n = fixnum-max + 1" |
1271 | (eqv? 1 (gcd fixnum-max (+ fixnum-max 1)))) | |
de142bea | 1272 | |
21e39e8f DH |
1273 | (pass-if "n = fixnum-min" |
1274 | (eqv? 1 (gcd fixnum-max fixnum-min))) | |
de142bea | 1275 | |
21e39e8f DH |
1276 | (pass-if "n = fixnum-min - 1" |
1277 | (eqv? 1 (gcd fixnum-max (- fixnum-min 1))))) | |
1278 | ||
1279 | (with-test-prefix "((+ fixnum-max 1) n)" | |
1280 | ||
1281 | (pass-if "n = 0" | |
1282 | (eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) 0))) | |
1283 | ||
1284 | (pass-if "n = 1" | |
1285 | (eqv? 1 (gcd (+ fixnum-max 1) 1))) | |
de142bea DH |
1286 | |
1287 | (pass-if "n = -1" | |
21e39e8f | 1288 | (eqv? 1 (gcd (+ fixnum-max 1) -1))) |
de142bea | 1289 | |
21e39e8f DH |
1290 | (pass-if "n = fixnum-max" |
1291 | (eqv? 1 (gcd (+ fixnum-max 1) fixnum-max))) | |
de142bea | 1292 | |
21e39e8f DH |
1293 | (pass-if "n = fixnum-max + 1" |
1294 | (eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) (+ fixnum-max 1)))) | |
de142bea | 1295 | |
21e39e8f DH |
1296 | (pass-if "n = fixnum-min" |
1297 | (eqv? (+ fixnum-max 1) (gcd (+ fixnum-max 1) fixnum-min))) | |
1298 | ||
1299 | (pass-if "n = fixnum-min - 1" | |
1300 | (eqv? 1 (gcd (+ fixnum-max 1) (- fixnum-min 1))))) | |
1301 | ||
1302 | (with-test-prefix "(fixnum-min n)" | |
1303 | ||
1304 | (pass-if "n = 0" | |
1305 | (eqv? (- fixnum-min) (gcd fixnum-min 0))) | |
1306 | ||
1307 | (pass-if "n = 1" | |
1308 | (eqv? 1 (gcd fixnum-min 1))) | |
de142bea DH |
1309 | |
1310 | (pass-if "n = -1" | |
21e39e8f DH |
1311 | (eqv? 1 (gcd fixnum-min -1))) |
1312 | ||
1313 | (pass-if "n = fixnum-max" | |
1314 | (eqv? 1 (gcd fixnum-min fixnum-max))) | |
1315 | ||
1316 | (pass-if "n = fixnum-max + 1" | |
1317 | (eqv? (+ fixnum-max 1) (gcd fixnum-min (+ fixnum-max 1)))) | |
de142bea | 1318 | |
21e39e8f DH |
1319 | (pass-if "n = fixnum-min" |
1320 | (eqv? (- fixnum-min) (gcd fixnum-min fixnum-min))) | |
1321 | ||
1322 | (pass-if "n = fixnum-min - 1" | |
1323 | (eqv? 1 (gcd fixnum-min (- fixnum-min 1))))) | |
1324 | ||
1325 | (with-test-prefix "((- fixnum-min 1) n)" | |
1326 | ||
1327 | (pass-if "n = 0" | |
1328 | (eqv? (- (- fixnum-min 1)) (gcd (- fixnum-min 1) 0))) | |
1329 | ||
1330 | (pass-if "n = 1" | |
1331 | (eqv? 1 (gcd (- fixnum-min 1) 1))) | |
1332 | ||
1333 | (pass-if "n = -1" | |
1334 | (eqv? 1 (gcd (- fixnum-min 1) -1))) | |
1335 | ||
1336 | (pass-if "n = fixnum-max" | |
1337 | (eqv? 1 (gcd (- fixnum-min 1) fixnum-max))) | |
1338 | ||
1339 | (pass-if "n = fixnum-max + 1" | |
1340 | (eqv? 1 (gcd (- fixnum-min 1) (+ fixnum-max 1)))) | |
1341 | ||
1342 | (pass-if "n = fixnum-min" | |
1343 | (eqv? 1 (gcd (- fixnum-min 1) fixnum-min))) | |
1344 | ||
1345 | (pass-if "n = fixnum-min - 1" | |
1346 | (eqv? (- (- fixnum-min 1)) (gcd (- fixnum-min 1) (- fixnum-min 1))))) | |
de142bea DH |
1347 | |
1348 | ;; Are wrong type arguments detected correctly? | |
1349 | ||
1350 | ) | |
1351 | ||
f29b3454 DH |
1352 | ;;; |
1353 | ;;; lcm | |
1354 | ;;; | |
1355 | ||
7c24e528 RB |
1356 | (with-test-prefix "lcm" |
1357 | ;; FIXME: more tests? | |
1358 | ;; (some of these are already in r4rs.test) | |
d389e966 | 1359 | (pass-if (documented? lcm)) |
7c24e528 RB |
1360 | (pass-if (= (lcm) 1)) |
1361 | (pass-if (= (lcm 32 -36) 288)) | |
1362 | (let ((big-n 115792089237316195423570985008687907853269984665640564039457584007913129639936) ; 2 ^ 256 | |
1363 | (lcm-of-big-n-and-11 1273712981610478149659280835095566986385969831322046204434033424087044426039296)) | |
1364 | (pass-if (= lcm-of-big-n-and-11 (lcm big-n 11))) | |
1365 | (pass-if (= lcm-of-big-n-and-11 (lcm 11 big-n 11))))) | |
1366 | ||
605f6980 MW |
1367 | ;;; |
1368 | ;;; rationalize | |
1369 | ;;; | |
1370 | (with-test-prefix "rationalize" | |
1371 | (pass-if (documented? rationalize)) | |
1372 | (pass-if (eqv? 2 (rationalize 4 2 ))) | |
1373 | (pass-if (eqv? -2 (rationalize -4 2 ))) | |
1374 | (pass-if (eqv? 2.0 (rationalize 4 2.0))) | |
1375 | (pass-if (eqv? -2.0 (rationalize -4.0 2 ))) | |
1376 | ||
1377 | (pass-if (eqv? 0 (rationalize 4 8 ))) | |
1378 | (pass-if (eqv? 0 (rationalize -4 8 ))) | |
1379 | (pass-if (eqv? 0.0 (rationalize 4 8.0))) | |
1380 | (pass-if (eqv? 0.0 (rationalize -4.0 8 ))) | |
1381 | ||
1382 | (pass-if (eqv? 0.0 (rationalize 3 +inf.0))) | |
1383 | (pass-if (eqv? 0.0 (rationalize -3 +inf.0))) | |
1384 | ||
55a8b708 MW |
1385 | (pass-if (real-nan? (rationalize +inf.0 +inf.0))) |
1386 | (pass-if (real-nan? (rationalize +nan.0 +inf.0))) | |
1387 | (pass-if (real-nan? (rationalize +nan.0 4))) | |
605f6980 MW |
1388 | (pass-if (eqv? +inf.0 (rationalize +inf.0 3))) |
1389 | ||
1390 | (pass-if (eqv? 3/10 (rationalize 3/10 0))) | |
1391 | (pass-if (eqv? -3/10 (rationalize -3/10 0))) | |
1392 | ||
1393 | (pass-if (eqv? 1/3 (rationalize 3/10 1/10))) | |
1394 | (pass-if (eqv? -1/3 (rationalize -3/10 1/10))) | |
1395 | ||
1396 | (pass-if (eqv? 1/3 (rationalize 3/10 -1/10))) | |
1397 | (pass-if (eqv? -1/3 (rationalize -3/10 -1/10))) | |
1398 | ||
1399 | (pass-if (test-eqv? (/ 1.0 3) (rationalize 0.3 1/10))) | |
1400 | (pass-if (test-eqv? (/ -1.0 3) (rationalize -0.3 1/10))) | |
1401 | (pass-if (test-eqv? (/ 1.0 3) (rationalize 0.3 -1/10))) | |
1402 | (pass-if (test-eqv? (/ -1.0 3) (rationalize -0.3 -1/10)))) | |
1403 | ||
f29b3454 DH |
1404 | ;;; |
1405 | ;;; number->string | |
1406 | ;;; | |
1407 | ||
7c24e528 RB |
1408 | (with-test-prefix "number->string" |
1409 | (let ((num->str->num | |
1410 | (lambda (n radix) | |
1411 | (string->number (number->string n radix) radix)))) | |
1412 | ||
1413 | (pass-if (documented? number->string)) | |
1414 | (pass-if (string=? (number->string 0) "0")) | |
1415 | (pass-if (string=? (number->string 171) "171")) | |
1416 | (pass-if (= (+ fixnum-max 1) (num->str->num (+ fixnum-max 1) 10))) | |
1417 | (pass-if (= (- fixnum-min 1) (num->str->num (- fixnum-min 1) 10))) | |
1418 | (pass-if (= (inf) (num->str->num (inf) 10))) | |
d39a7b58 MV |
1419 | (pass-if (= 1.3 (num->str->num 1.3 10))) |
1420 | ||
eb73f94b MV |
1421 | ;; XXX - some results depend on whether Guile is compiled optimzed |
1422 | ;; or not. It is clearly undesirable to have number->string to be | |
1423 | ;; influenced by this. | |
1424 | ||
3740c788 | 1425 | (pass-if (string=? (number->string 35.25 36) "z.9")) |
eb73f94b MV |
1426 | (pass-if (or (string=? (number->string 0.25 2) "0.01") |
1427 | (string=? (number->string 0.25 2) "0.010"))) | |
3740c788 | 1428 | (pass-if (string=? (number->string 255.0625 16) "ff.1")) |
d39a7b58 | 1429 | (pass-if (string=? (number->string (/ 1 3) 3) "1/10")) |
23f2b9a3 | 1430 | |
a6f3af16 | 1431 | (pass-if (string=? (number->string 10) "10")) |
3740c788 | 1432 | (pass-if (string=? (number->string 10 11) "a")) |
a6f3af16 AW |
1433 | (pass-if (string=? (number->string 36 36) "10")) |
1434 | (pass-if (= (num->str->num 36 36) 36)) | |
1435 | (pass-if (= (string->number "z" 36) 35)) | |
1436 | (pass-if (= (string->number "Z" 36) 35)) | |
1437 | (pass-if (not (string->number "Z" 35))) | |
3740c788 | 1438 | (pass-if (string=? (number->string 35 36) "z")) |
a6f3af16 AW |
1439 | (pass-if (= (num->str->num 35 36) 35)) |
1440 | ||
23f2b9a3 KR |
1441 | ;; Numeric conversion from decimal is not precise, in its current |
1442 | ;; implementation, so 11.333... and 1.324... can't be expected to | |
1443 | ;; reliably come out to precise values. These tests did actually work | |
1444 | ;; for a while, but something in gcc changed, affecting the conversion | |
1445 | ;; code. | |
1446 | ;; | |
1447 | ;; (pass-if (or (string=? (number->string 11.33333333333333333 12) | |
1448 | ;; "B.4") | |
1449 | ;; (string=? (number->string 11.33333333333333333 12) | |
1450 | ;; "B.400000000000009"))) | |
1451 | ;; (pass-if (or (string=? (number->string 1.324e44 16) | |
1452 | ;; "5.EFE0A14FAFEe24") | |
1453 | ;; (string=? (number->string 1.324e44 16) | |
1454 | ;; "5.EFE0A14FAFDF8e24"))) | |
1455 | )) | |
7c24e528 | 1456 | |
f29b3454 DH |
1457 | ;;; |
1458 | ;;; string->number | |
1459 | ;;; | |
1460 | ||
2f4a254a DH |
1461 | (with-test-prefix "string->number" |
1462 | ||
ff758237 | 1463 | (pass-if "documented?" |
2f4a254a DH |
1464 | (documented? string->number)) |
1465 | ||
1466 | (pass-if "non number strings" | |
1467 | (for-each (lambda (x) (if (string->number x) (throw 'fail))) | |
569c483b | 1468 | '("" "q" "1q" "6+7iq" "8+9q" "10+11" "13+" "18@19q" "20@q" "23@" |
2f4a254a | 1469 | "+25iq" "26i" "-q" "-iq" "i" "5#.0" "8/" "10#11" ".#" "." |
569c483b | 1470 | "#o.2" "3.4q" "15.16e17q" "18.19e+q" ".q" ".17#18" "10q" "#b2" |
2f4a254a DH |
1471 | "#b3" "#b4" "#b5" "#b6" "#b7" "#b8" "#b9" "#ba" "#bb" "#bc" |
1472 | "#bd" "#be" "#bf" "#q" "#b#b1" "#o#o1" "#d#d1" "#x#x1" "#e#e1" | |
1473 | "#i#i1" "12@12+0i")) | |
1474 | #t) | |
1475 | ||
b7d9b1cf DH |
1476 | (pass-if "valid number strings" |
1477 | (for-each (lambda (couple) | |
1478 | (apply | |
1479 | (lambda (x y) | |
9dd9857f MV |
1480 | (let ((xx (string->number x))) |
1481 | (if (or (eq? xx #f) (not (eqv? xx y))) | |
ca2b31fe MV |
1482 | (begin |
1483 | (pk x y) | |
1484 | (throw 'fail))))) | |
b7d9b1cf DH |
1485 | couple)) |
1486 | `(;; Radix: | |
1487 | ("#b0" 0) ("#B0" 0) ("#b1" 1) ("#B1" 1) ("#o0" 0) ("#O0" 0) | |
1488 | ("#o1" 1) ("#O1" 1) ("#o2" 2) ("#O2" 2) ("#o3" 3) ("#O3" 3) | |
1489 | ("#o4" 4) ("#O4" 4) ("#o5" 5) ("#O5" 5) ("#o6" 6) ("#O6" 6) | |
1490 | ("#o7" 7) ("#O7" 7) ("#d0" 0) ("#D0" 0) ("#d1" 1) ("#D1" 1) | |
1491 | ("#d2" 2) ("#D2" 2) ("#d3" 3) ("#D3" 3) ("#d4" 4) ("#D4" 4) | |
1492 | ("#d5" 5) ("#D5" 5) ("#d6" 6) ("#D6" 6) ("#d7" 7) ("#D7" 7) | |
1493 | ("#d8" 8) ("#D8" 8) ("#d9" 9) ("#D9" 9) | |
1494 | ("#xa" 10) ("#Xa" 10) ("#xb" 11) ("#Xb" 11) | |
1495 | ("#xc" 12) ("#Xc" 12) ("#xd" 13) ("#Xd" 13) | |
1496 | ("#xe" 14) ("#Xe" 14) ("#xf" 15) ("#Xf" 15) | |
1497 | ("#b1010" 10) | |
1498 | ("#o12345670" 2739128) | |
1499 | ("#d1234567890" 1234567890) | |
1500 | ("#x1234567890abcdef" 1311768467294899695) | |
1501 | ;; Exactness: | |
ca2b31fe | 1502 | ("#e1" 1) ("#e1.2" 12/10) |
9dd9857f | 1503 | ("#i1.1" 1.1) ("#i1" 1.0) |
b7d9b1cf DH |
1504 | ;; Integers: |
1505 | ("1" ,(1+ 0)) ("23" ,(+ 9 9 5)) ("-1" ,(- 0 1)) | |
1506 | ("-45" ,(- 0 45)) ("2#" 20.0) ("2##" 200.0) ("12##" 1200.0) | |
1507 | ("#b#i100" 4.0) | |
9dd9857f MV |
1508 | ;; Fractions: |
1509 | ("1/1" 1) ("1/2" 1/2) ("-1/2" -1/2) ("1#/1" 10.0) | |
1510 | ("10/1#" 1.0) ("1#/1#" 1.0) ("#e9/10" 9/10) ("#e10/1#" 1) | |
b7d9b1cf DH |
1511 | ("#i6/8" 0.75) ("#i1/1" 1.0) |
1512 | ;; Decimal numbers: | |
1513 | ;; * <uinteger 10> <suffix> | |
1514 | ("1e2" 100.0) ("1E2" 100.0) ("1s2" 100.0) ("1S2" 100.0) | |
1515 | ("1f2" 100.0) ("1F2" 100.0) ("1d2" 100.0) ("1D2" 100.0) | |
1516 | ("1l2" 100.0) ("1L2" 100.0) ("1e+2" 100.0) ("1e-2" 0.01) | |
1517 | ;; * . <digit 10>+ #* <suffix> | |
1518 | (".1" .1) (".0123456789" 123456789e-10) (".16#" 0.16) | |
1519 | (".0123456789e10" 123456789.0) (".16#e3" 160.0) ("#d.3" 0.3) | |
1520 | ;; * <digit 10>+ . <digit 10>* #* <suffix> | |
1521 | ("3." ,(exact->inexact 3)) ("3.e0" ,(exact->inexact 3)) | |
1522 | ("3.1" ,(exact->inexact 31/10)) ("3.1e0" 3.1) ("3.1#" 3.1) | |
1523 | ("3.1#e0" 3.1) | |
1524 | ;; * <digit 10>+ #+ . #* <suffix> | |
1525 | ("3#." 30.0) ("3#.e0" 30.0) ("3#.#" 30.0) ("3#.#e0" 30.0) | |
9d427b2c MW |
1526 | )) |
1527 | #t) | |
1528 | ||
1529 | (pass-if "valid complex number strings" | |
1530 | (for-each (lambda (triple) | |
1531 | (apply | |
1532 | (lambda (str re im) | |
1533 | (let ((z (string->number str))) | |
1534 | (if (or (eq? z #f) | |
1535 | (not (and (eqv? (real-part z) re) | |
1536 | (eqv? (imag-part z) im)))) | |
1537 | (begin | |
1538 | (pk str re im) | |
1539 | (throw 'fail))))) | |
1540 | triple)) | |
1541 | `(("1@0" 1 0) ("1@+0" 1 0) ("1@-0" 1 0) ("1/2@0" 1/2 0) | |
1542 | ("1.0@0" 1.0 0) ("1.0@-0" 1.0 0) | |
1543 | ("#e1@0" 1 0) ("#e1@+0" 1 0) ("#e1@-0" 1 0) ("#e0.5@0.0" 1/2 0) | |
1544 | ("#e1.0@0" 1 0) ("#e1.0@-0" 1 0) | |
1545 | ("#i1@0" 1.0 0.0) ("#i1@+0" 1.0 0.0) ("#i1@-0" 1.0 -0.0) ("#i1/2@0" 0.5 0.0) | |
1546 | ("#i1.0@0" 1.0 0.0) ("#i1.0@-0" 1.0 -0.0) | |
1547 | ("1@+0.0" 1.0 0.0) ("1.0@-0.0" 1.0 -0.0) | |
1548 | ("2+3i" 2.0 3.0) ("4-5i" 4.0 -5.0) | |
1549 | ("1+i" 1.0 1.0) ("1-i" 1.0 -1.0) ("+1i" 0.0 1.0) ("-1i" 0.0 -1.0) | |
1550 | ("+i" 0.0 1.0) ("-i" 0.0 -1.0) | |
1551 | ("1.0+.1i" 1.0 0.1) ("1.0-.1i" 1.0 -0.1) | |
1552 | (".1+.0i" 0.1 0.0) ("1.+.0i" 1.0 0.0) (".1+.1i" 0.1 0.1) | |
1553 | ("1e1+.1i" 10.0 0.1) | |
1554 | ("0@+nan.0" 0 0) ("0@+inf.0" 0 0) ("0@-inf.0" 0 0) | |
1555 | ("0.0@+nan.0" 0.0 0.0) ("0.0@+inf.0" 0.0 0.0) ("0.0@-inf.0" 0.0 0.0) | |
1556 | ("#i0@+nan.0" 0.0 0.0) ("#i0@+inf.0" 0.0 0.0) ("#i0@-inf.0" 0.0 0.0) | |
1557 | ("0.0@1" 0.0 0.0) ("0.0@2" -0.0 0.0) ("0.0@4" -0.0 -0.0) ("0.0@5" 0.0 -0.0) | |
40f89215 | 1558 | )) |
b7d9b1cf DH |
1559 | #t) |
1560 | ||
2f4a254a DH |
1561 | (pass-if-exception "exponent too big" |
1562 | exception:out-of-range | |
48e78ba6 KR |
1563 | (string->number "12.13e141414")) |
1564 | ||
1565 | ;; in guile 1.6.7 and earlier, bad polar forms (where the conversion of | |
1566 | ;; the angle gave #f) caused a segv | |
1567 | (pass-if "1@a" | |
1568 | (eq? #f (string->number "1@a")))) | |
2f4a254a | 1569 | |
f29b3454 DH |
1570 | ;;; |
1571 | ;;; number? | |
1572 | ;;; | |
1573 | ||
7c24e528 RB |
1574 | (with-test-prefix "number?" |
1575 | (pass-if (documented? number?)) | |
1576 | (pass-if (number? 0)) | |
1577 | (pass-if (number? 7)) | |
1578 | (pass-if (number? -7)) | |
1579 | (pass-if (number? 1.3)) | |
1580 | (pass-if (number? (+ 1 fixnum-max))) | |
1581 | (pass-if (number? (- 1 fixnum-min))) | |
1582 | (pass-if (number? 3+4i)) | |
4d332f19 DH |
1583 | (pass-if (not (number? #\a))) |
1584 | (pass-if (not (number? "a"))) | |
1585 | (pass-if (not (number? (make-vector 0)))) | |
1586 | (pass-if (not (number? (cons 1 2)))) | |
1587 | (pass-if (not (number? #t))) | |
1588 | (pass-if (not (number? (lambda () #t)))) | |
1589 | (pass-if (not (number? (current-input-port))))) | |
7c24e528 | 1590 | |
f29b3454 DH |
1591 | ;;; |
1592 | ;;; complex? | |
1593 | ;;; | |
1594 | ||
7c24e528 RB |
1595 | (with-test-prefix "complex?" |
1596 | (pass-if (documented? complex?)) | |
1597 | (pass-if (complex? 0)) | |
1598 | (pass-if (complex? 7)) | |
1599 | (pass-if (complex? -7)) | |
1600 | (pass-if (complex? (+ 1 fixnum-max))) | |
1601 | (pass-if (complex? (- 1 fixnum-min))) | |
1602 | (pass-if (complex? 1.3)) | |
1603 | (pass-if (complex? 3+4i)) | |
4d332f19 DH |
1604 | (pass-if (not (complex? #\a))) |
1605 | (pass-if (not (complex? "a"))) | |
1606 | (pass-if (not (complex? (make-vector 0)))) | |
1607 | (pass-if (not (complex? (cons 1 2)))) | |
1608 | (pass-if (not (complex? #t))) | |
1609 | (pass-if (not (complex? (lambda () #t)))) | |
1610 | (pass-if (not (complex? (current-input-port))))) | |
7c24e528 | 1611 | |
f29b3454 DH |
1612 | ;;; |
1613 | ;;; real? | |
1614 | ;;; | |
1615 | ||
7c24e528 RB |
1616 | (with-test-prefix "real?" |
1617 | (pass-if (documented? real?)) | |
1618 | (pass-if (real? 0)) | |
1619 | (pass-if (real? 7)) | |
1620 | (pass-if (real? -7)) | |
1621 | (pass-if (real? (+ 1 fixnum-max))) | |
1622 | (pass-if (real? (- 1 fixnum-min))) | |
1623 | (pass-if (real? 1.3)) | |
c960e556 MW |
1624 | (pass-if (real? +inf.0)) |
1625 | (pass-if (real? -inf.0)) | |
1626 | (pass-if (real? +nan.0)) | |
1627 | (pass-if (not (real? +inf.0-inf.0i))) | |
1628 | (pass-if (not (real? +nan.0+nan.0i))) | |
4d332f19 DH |
1629 | (pass-if (not (real? 3+4i))) |
1630 | (pass-if (not (real? #\a))) | |
1631 | (pass-if (not (real? "a"))) | |
1632 | (pass-if (not (real? (make-vector 0)))) | |
1633 | (pass-if (not (real? (cons 1 2)))) | |
1634 | (pass-if (not (real? #t))) | |
1635 | (pass-if (not (real? (lambda () #t)))) | |
1636 | (pass-if (not (real? (current-input-port))))) | |
7c24e528 | 1637 | |
f29b3454 | 1638 | ;;; |
c960e556 | 1639 | ;;; rational? |
f29b3454 DH |
1640 | ;;; |
1641 | ||
7c24e528 RB |
1642 | (with-test-prefix "rational?" |
1643 | (pass-if (documented? rational?)) | |
1644 | (pass-if (rational? 0)) | |
1645 | (pass-if (rational? 7)) | |
1646 | (pass-if (rational? -7)) | |
1647 | (pass-if (rational? (+ 1 fixnum-max))) | |
1648 | (pass-if (rational? (- 1 fixnum-min))) | |
1649 | (pass-if (rational? 1.3)) | |
c960e556 MW |
1650 | (pass-if (not (rational? +inf.0))) |
1651 | (pass-if (not (rational? -inf.0))) | |
1652 | (pass-if (not (rational? +nan.0))) | |
1653 | (pass-if (not (rational? +inf.0-inf.0i))) | |
1654 | (pass-if (not (rational? +nan.0+nan.0i))) | |
4d332f19 DH |
1655 | (pass-if (not (rational? 3+4i))) |
1656 | (pass-if (not (rational? #\a))) | |
1657 | (pass-if (not (rational? "a"))) | |
1658 | (pass-if (not (rational? (make-vector 0)))) | |
1659 | (pass-if (not (rational? (cons 1 2)))) | |
1660 | (pass-if (not (rational? #t))) | |
1661 | (pass-if (not (rational? (lambda () #t)))) | |
1662 | (pass-if (not (rational? (current-input-port))))) | |
7c24e528 | 1663 | |
f29b3454 DH |
1664 | ;;; |
1665 | ;;; integer? | |
1666 | ;;; | |
1667 | ||
7c24e528 RB |
1668 | (with-test-prefix "integer?" |
1669 | (pass-if (documented? integer?)) | |
1670 | (pass-if (integer? 0)) | |
1671 | (pass-if (integer? 7)) | |
1672 | (pass-if (integer? -7)) | |
1673 | (pass-if (integer? (+ 1 fixnum-max))) | |
1674 | (pass-if (integer? (- 1 fixnum-min))) | |
1675 | (pass-if (and (= 3+0i (round 3+0i)) (integer? 3+0i))) | |
1676 | (pass-if (and (= 1.0 (round 1.0)) (integer? 1.0))) | |
4d332f19 | 1677 | (pass-if (not (integer? 1.3))) |
8e43ed5d AW |
1678 | (pass-if (not (integer? +inf.0))) |
1679 | (pass-if (not (integer? -inf.0))) | |
c1122753 | 1680 | (pass-if (not (integer? +nan.0))) |
c7218482 MW |
1681 | (pass-if (not (integer? +inf.0-inf.0i))) |
1682 | (pass-if (not (integer? +nan.0+nan.0i))) | |
4d332f19 DH |
1683 | (pass-if (not (integer? 3+4i))) |
1684 | (pass-if (not (integer? #\a))) | |
1685 | (pass-if (not (integer? "a"))) | |
1686 | (pass-if (not (integer? (make-vector 0)))) | |
1687 | (pass-if (not (integer? (cons 1 2)))) | |
1688 | (pass-if (not (integer? #t))) | |
1689 | (pass-if (not (integer? (lambda () #t)))) | |
1690 | (pass-if (not (integer? (current-input-port))))) | |
7c24e528 | 1691 | |
f29b3454 DH |
1692 | ;;; |
1693 | ;;; inexact? | |
1694 | ;;; | |
1695 | ||
7c24e528 RB |
1696 | (with-test-prefix "inexact?" |
1697 | (pass-if (documented? inexact?)) | |
4d332f19 DH |
1698 | (pass-if (not (inexact? 0))) |
1699 | (pass-if (not (inexact? 7))) | |
1700 | (pass-if (not (inexact? -7))) | |
1701 | (pass-if (not (inexact? (+ 1 fixnum-max)))) | |
1702 | (pass-if (not (inexact? (- 1 fixnum-min)))) | |
7c24e528 RB |
1703 | (pass-if (inexact? 1.3)) |
1704 | (pass-if (inexact? 3.1+4.2i)) | |
41df63cf MW |
1705 | (pass-if (inexact? +inf.0)) |
1706 | (pass-if (inexact? -inf.0)) | |
1707 | (pass-if (inexact? +nan.0)) | |
ca2b31fe MV |
1708 | (pass-if-exception "char" |
1709 | exception:wrong-type-arg | |
1710 | (not (inexact? #\a))) | |
1711 | (pass-if-exception "string" | |
1712 | exception:wrong-type-arg | |
1713 | (not (inexact? "a"))) | |
1714 | (pass-if-exception "vector" | |
1715 | exception:wrong-type-arg | |
1716 | (not (inexact? (make-vector 0)))) | |
1717 | (pass-if-exception "cons" | |
1718 | exception:wrong-type-arg | |
1719 | (not (inexact? (cons 1 2)))) | |
1720 | (pass-if-exception "bool" | |
1721 | exception:wrong-type-arg | |
1722 | (not (inexact? #t))) | |
1723 | (pass-if-exception "procedure" | |
1724 | exception:wrong-type-arg | |
1725 | (not (inexact? (lambda () #t)))) | |
1726 | (pass-if-exception "port" | |
1727 | exception:wrong-type-arg | |
1728 | (not (inexact? (current-input-port))))) | |
7c24e528 | 1729 | |
47ae1f0e DH |
1730 | ;;; |
1731 | ;;; equal? | |
1732 | ;;; | |
1733 | ||
1734 | (with-test-prefix "equal?" | |
1735 | (pass-if (documented? equal?)) | |
2e6e1933 MW |
1736 | |
1737 | ;; The following test will fail on platforms | |
1738 | ;; without distinct signed zeroes 0.0 and -0.0. | |
1739 | (pass-if (not (equal? 0.0 -0.0))) | |
1740 | ||
47ae1f0e DH |
1741 | (pass-if (equal? 0 0)) |
1742 | (pass-if (equal? 7 7)) | |
1743 | (pass-if (equal? -7 -7)) | |
1744 | (pass-if (equal? (+ 1 fixnum-max) (+ 1 fixnum-max))) | |
1745 | (pass-if (equal? (- fixnum-min 1) (- fixnum-min 1))) | |
2e6e1933 MW |
1746 | (pass-if (equal? 0.0 0.0)) |
1747 | (pass-if (equal? -0.0 -0.0)) | |
c7218482 MW |
1748 | (pass-if (equal? 0.0+0.0i 0.0+0.0i)) |
1749 | (pass-if (equal? 0.0-0.0i 0.0-0.0i)) | |
1750 | (pass-if (equal? -0.0+0.0i -0.0+0.0i)) | |
47ae1f0e | 1751 | (pass-if (not (equal? 0 1))) |
2e6e1933 MW |
1752 | (pass-if (not (equal? 0 0.0))) |
1753 | (pass-if (not (equal? 1 1.0))) | |
1754 | (pass-if (not (equal? 0.0 0))) | |
1755 | (pass-if (not (equal? 1.0 1))) | |
1756 | (pass-if (not (equal? -1.0 -1))) | |
c7218482 MW |
1757 | (pass-if (not (equal? 1.0 1.0+0.0i))) |
1758 | (pass-if (not (equal? 0.0 0.0+0.0i))) | |
1759 | (pass-if (not (equal? 0.0+0.0i 0.0-0.0i))) | |
1760 | (pass-if (not (equal? 0.0+0.0i -0.0+0.0i))) | |
47ae1f0e DH |
1761 | (pass-if (not (equal? fixnum-max (+ 1 fixnum-max)))) |
1762 | (pass-if (not (equal? (+ 1 fixnum-max) fixnum-max))) | |
1763 | (pass-if (not (equal? (+ 1 fixnum-max) (+ 2 fixnum-max)))) | |
1764 | (pass-if (not (equal? fixnum-min (- fixnum-min 1)))) | |
1765 | (pass-if (not (equal? (- fixnum-min 1) fixnum-min))) | |
1766 | (pass-if (not (equal? (- fixnum-min 1) (- fixnum-min 2)))) | |
1767 | (pass-if (not (equal? (+ fixnum-max 1) (- fixnum-min 1)))) | |
1768 | ||
1769 | (pass-if (not (equal? (ash 1 256) +inf.0))) | |
1770 | (pass-if (not (equal? +inf.0 (ash 1 256)))) | |
1771 | (pass-if (not (equal? (ash 1 256) -inf.0))) | |
1772 | (pass-if (not (equal? -inf.0 (ash 1 256)))) | |
1773 | ||
1774 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating Inf as 2^1024, make | |
1775 | ;; sure we've avoided that | |
1776 | (pass-if (not (equal? (ash 1 1024) +inf.0))) | |
1777 | (pass-if (not (equal? +inf.0 (ash 1 1024)))) | |
1778 | (pass-if (not (equal? (- (ash 1 1024)) -inf.0))) | |
1779 | (pass-if (not (equal? -inf.0 (- (ash 1 1024))))) | |
1780 | ||
2e6e1933 MW |
1781 | (pass-if (equal? +nan.0 +nan.0)) |
1782 | (pass-if (equal? +nan.0 +nan.0)) | |
1783 | (pass-if (not (equal? +nan.0 0.0+nan.0i))) | |
1784 | ||
47ae1f0e DH |
1785 | (pass-if (not (equal? 0 +nan.0))) |
1786 | (pass-if (not (equal? +nan.0 0))) | |
1787 | (pass-if (not (equal? 1 +nan.0))) | |
1788 | (pass-if (not (equal? +nan.0 1))) | |
1789 | (pass-if (not (equal? -1 +nan.0))) | |
1790 | (pass-if (not (equal? +nan.0 -1))) | |
1791 | ||
1792 | (pass-if (not (equal? (ash 1 256) +nan.0))) | |
1793 | (pass-if (not (equal? +nan.0 (ash 1 256)))) | |
1794 | (pass-if (not (equal? (- (ash 1 256)) +nan.0))) | |
1795 | (pass-if (not (equal? +nan.0 (- (ash 1 256))))) | |
1796 | ||
1797 | (pass-if (not (equal? (ash 1 8192) +nan.0))) | |
1798 | (pass-if (not (equal? +nan.0 (ash 1 8192)))) | |
1799 | (pass-if (not (equal? (- (ash 1 8192)) +nan.0))) | |
1800 | (pass-if (not (equal? +nan.0 (- (ash 1 8192))))) | |
1801 | ||
1802 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make | |
1803 | ;; sure we've avoided that | |
1804 | (pass-if (not (equal? (ash 3 1023) +nan.0))) | |
1805 | (pass-if (not (equal? +nan.0 (ash 3 1023))))) | |
1806 | ||
2e6e1933 MW |
1807 | ;;; |
1808 | ;;; eqv? | |
1809 | ;;; | |
1810 | ||
1811 | (with-test-prefix "eqv?" | |
1812 | (pass-if (documented? eqv?)) | |
1813 | ||
1814 | ;; The following test will fail on platforms | |
1815 | ;; without distinct signed zeroes 0.0 and -0.0. | |
1816 | (pass-if (not (eqv? 0.0 -0.0))) | |
1817 | ||
1818 | (pass-if (eqv? 0 0)) | |
1819 | (pass-if (eqv? 7 7)) | |
1820 | (pass-if (eqv? -7 -7)) | |
1821 | (pass-if (eqv? (+ 1 fixnum-max) (+ 1 fixnum-max))) | |
1822 | (pass-if (eqv? (- fixnum-min 1) (- fixnum-min 1))) | |
1823 | (pass-if (eqv? 0.0 0.0)) | |
1824 | (pass-if (eqv? -0.0 -0.0)) | |
c7218482 MW |
1825 | (pass-if (eqv? 0.0+0.0i 0.0+0.0i)) |
1826 | (pass-if (eqv? 0.0-0.0i 0.0-0.0i)) | |
1827 | (pass-if (eqv? -0.0+0.0i -0.0+0.0i)) | |
1828 | (pass-if (not (eqv? 0.0 -0.0))) | |
1829 | (pass-if (not (eqv? 0.0 0.0+0.0i))) | |
1830 | (pass-if (not (eqv? 0.0+0.0i 0.0-0.0i))) | |
1831 | (pass-if (not (eqv? 0.0+0.0i -0.0+0.0i))) | |
2e6e1933 MW |
1832 | (pass-if (not (eqv? 0 1))) |
1833 | (pass-if (not (eqv? 0 0.0))) | |
1834 | (pass-if (not (eqv? 1 1.0))) | |
1835 | (pass-if (not (eqv? 0.0 0))) | |
1836 | (pass-if (not (eqv? 1.0 1))) | |
1837 | (pass-if (not (eqv? -1.0 -1))) | |
c7218482 MW |
1838 | (pass-if (not (eqv? 1.0 1.0+0.0i))) |
1839 | (pass-if (not (eqv? 0.0 0.0+0.0i))) | |
2e6e1933 MW |
1840 | (pass-if (not (eqv? fixnum-max (+ 1 fixnum-max)))) |
1841 | (pass-if (not (eqv? (+ 1 fixnum-max) fixnum-max))) | |
1842 | (pass-if (not (eqv? (+ 1 fixnum-max) (+ 2 fixnum-max)))) | |
1843 | (pass-if (not (eqv? fixnum-min (- fixnum-min 1)))) | |
1844 | (pass-if (not (eqv? (- fixnum-min 1) fixnum-min))) | |
1845 | (pass-if (not (eqv? (- fixnum-min 1) (- fixnum-min 2)))) | |
1846 | (pass-if (not (eqv? (+ fixnum-max 1) (- fixnum-min 1)))) | |
1847 | ||
1848 | (pass-if (not (eqv? (ash 1 256) +inf.0))) | |
1849 | (pass-if (not (eqv? +inf.0 (ash 1 256)))) | |
1850 | (pass-if (not (eqv? (ash 1 256) -inf.0))) | |
1851 | (pass-if (not (eqv? -inf.0 (ash 1 256)))) | |
1852 | ||
1853 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating Inf as 2^1024, make | |
1854 | ;; sure we've avoided that | |
1855 | (pass-if (not (eqv? (ash 1 1024) +inf.0))) | |
1856 | (pass-if (not (eqv? +inf.0 (ash 1 1024)))) | |
1857 | (pass-if (not (eqv? (- (ash 1 1024)) -inf.0))) | |
1858 | (pass-if (not (eqv? -inf.0 (- (ash 1 1024))))) | |
1859 | ||
1860 | (pass-if (eqv? +nan.0 +nan.0)) | |
1861 | (pass-if (not (eqv? +nan.0 0.0+nan.0i))) | |
1862 | ||
1863 | (pass-if (not (eqv? 0 +nan.0))) | |
1864 | (pass-if (not (eqv? +nan.0 0))) | |
1865 | (pass-if (not (eqv? 1 +nan.0))) | |
1866 | (pass-if (not (eqv? +nan.0 1))) | |
1867 | (pass-if (not (eqv? -1 +nan.0))) | |
1868 | (pass-if (not (eqv? +nan.0 -1))) | |
1869 | ||
1870 | (pass-if (not (eqv? (ash 1 256) +nan.0))) | |
1871 | (pass-if (not (eqv? +nan.0 (ash 1 256)))) | |
1872 | (pass-if (not (eqv? (- (ash 1 256)) +nan.0))) | |
1873 | (pass-if (not (eqv? +nan.0 (- (ash 1 256))))) | |
1874 | ||
1875 | (pass-if (not (eqv? (ash 1 8192) +nan.0))) | |
1876 | (pass-if (not (eqv? +nan.0 (ash 1 8192)))) | |
1877 | (pass-if (not (eqv? (- (ash 1 8192)) +nan.0))) | |
1878 | (pass-if (not (eqv? +nan.0 (- (ash 1 8192))))) | |
1879 | ||
1880 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make | |
1881 | ;; sure we've avoided that | |
1882 | (pass-if (not (eqv? (ash 3 1023) +nan.0))) | |
1883 | (pass-if (not (eqv? +nan.0 (ash 3 1023))))) | |
1884 | ||
f29b3454 DH |
1885 | ;;; |
1886 | ;;; = | |
1887 | ;;; | |
1888 | ||
7c24e528 | 1889 | (with-test-prefix "=" |
8a1f4f98 | 1890 | (pass-if (documented? =)) |
7c24e528 RB |
1891 | (pass-if (= 7 7)) |
1892 | (pass-if (= -7 -7)) | |
c7218482 MW |
1893 | (pass-if (= 1.0 1)) |
1894 | (pass-if (= 1 1.0)) | |
1895 | (pass-if (= -1 -1.0)) | |
1896 | (pass-if (= 0.0 0.0)) | |
1897 | (pass-if (= 0.0 -0.0)) | |
1898 | (pass-if (= 1 1.0+0.0i)) | |
1899 | ||
1900 | (pass-if (= 0 0)) | |
1901 | (pass-if (= 0 0.0)) | |
1902 | (pass-if (= 0 -0.0)) | |
1903 | (pass-if (= 0 0.0+0.0i)) | |
1904 | (pass-if (= 0 0.0-0.0i)) | |
1905 | (pass-if (= 0 0.0+0.0i)) | |
1906 | (pass-if (= 0 -0.0-0.0i)) | |
1907 | ||
1908 | (pass-if (= 0 0)) | |
1909 | (pass-if (= 0.0 0)) | |
1910 | (pass-if (= -0.0 0)) | |
1911 | (pass-if (= 0.0+0.0i 0)) | |
1912 | (pass-if (= 0.0-0.0i 0)) | |
1913 | (pass-if (= 0.0+0.0i 0)) | |
1914 | (pass-if (= -0.0-0.0i 0)) | |
1915 | ||
1916 | (pass-if (= 0.0+0.0i 0.0-0.0i)) | |
1917 | (pass-if (= 0.0+0.0i -0.0+0.0i)) | |
1918 | ||
7c24e528 | 1919 | (pass-if (= (+ 1 fixnum-max) (+ 1 fixnum-max))) |
47ae1f0e | 1920 | (pass-if (= (- fixnum-min 1) (- fixnum-min 1))) |
4d332f19 DH |
1921 | (pass-if (not (= 0 1))) |
1922 | (pass-if (not (= fixnum-max (+ 1 fixnum-max)))) | |
1923 | (pass-if (not (= (+ 1 fixnum-max) fixnum-max))) | |
47ae1f0e | 1924 | (pass-if (not (= (+ 1 fixnum-max) (+ 2 fixnum-max)))) |
4d332f19 DH |
1925 | (pass-if (not (= fixnum-min (- fixnum-min 1)))) |
1926 | (pass-if (not (= (- fixnum-min 1) fixnum-min))) | |
47ae1f0e | 1927 | (pass-if (not (= (- fixnum-min 1) (- fixnum-min 2)))) |
4d332f19 | 1928 | (pass-if (not (= (+ fixnum-max 1) (- fixnum-min 1)))) |
2cfcaed5 | 1929 | |
adda36ed KR |
1930 | (pass-if (not (= (ash 1 256) +inf.0))) |
1931 | (pass-if (not (= +inf.0 (ash 1 256)))) | |
1932 | (pass-if (not (= (ash 1 256) -inf.0))) | |
1933 | (pass-if (not (= -inf.0 (ash 1 256)))) | |
1934 | ||
1935 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating Inf as 2^1024, make | |
1936 | ;; sure we've avoided that | |
1937 | (pass-if (not (= (ash 1 1024) +inf.0))) | |
1938 | (pass-if (not (= +inf.0 (ash 1 1024)))) | |
1939 | (pass-if (not (= (- (ash 1 1024)) -inf.0))) | |
1940 | (pass-if (not (= -inf.0 (- (ash 1 1024))))) | |
1941 | ||
2cfcaed5 KR |
1942 | (pass-if (not (= +nan.0 +nan.0))) |
1943 | (pass-if (not (= 0 +nan.0))) | |
1944 | (pass-if (not (= +nan.0 0))) | |
1945 | (pass-if (not (= 1 +nan.0))) | |
1946 | (pass-if (not (= +nan.0 1))) | |
1947 | (pass-if (not (= -1 +nan.0))) | |
1948 | (pass-if (not (= +nan.0 -1))) | |
1949 | ||
1950 | (pass-if (not (= (ash 1 256) +nan.0))) | |
1951 | (pass-if (not (= +nan.0 (ash 1 256)))) | |
1952 | (pass-if (not (= (- (ash 1 256)) +nan.0))) | |
1953 | (pass-if (not (= +nan.0 (- (ash 1 256))))) | |
1954 | ||
1955 | (pass-if (not (= (ash 1 8192) +nan.0))) | |
1956 | (pass-if (not (= +nan.0 (ash 1 8192)))) | |
1957 | (pass-if (not (= (- (ash 1 8192)) +nan.0))) | |
1958 | (pass-if (not (= +nan.0 (- (ash 1 8192))))) | |
1959 | ||
1960 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make | |
1961 | ;; sure we've avoided that | |
1962 | (pass-if (not (= (ash 3 1023) +nan.0))) | |
2a8b5e04 KR |
1963 | (pass-if (not (= +nan.0 (ash 3 1023)))) |
1964 | ||
1965 | (pass-if (= 1/2 0.5)) | |
1966 | (pass-if (not (= 1/3 0.333333333333333333333333333333333))) | |
1967 | (pass-if (not (= 2/3 0.5))) | |
1968 | (pass-if (not (= 0.5 (+ 1/2 (/ 1 (ash 1 1000)))))) | |
1969 | ||
1970 | (pass-if (= 1/2 0.5+0i)) | |
1971 | (pass-if (not (= 0.333333333333333333333333333333333 1/3))) | |
1972 | (pass-if (not (= 2/3 0.5+0i))) | |
1973 | (pass-if (not (= 1/2 0+0.5i))) | |
1974 | ||
1975 | (pass-if (= 0.5 1/2)) | |
1976 | (pass-if (not (= 0.5 2/3))) | |
1977 | (pass-if (not (= (+ 1/2 (/ 1 (ash 1 1000))) 0.5))) | |
1978 | ||
1979 | (pass-if (= 0.5+0i 1/2)) | |
1980 | (pass-if (not (= 0.5+0i 2/3))) | |
6f6847fa KR |
1981 | (pass-if (not (= 0+0.5i 1/2))) |
1982 | ||
1983 | ;; prior to guile 1.8, inum/flonum comparisons were done just by | |
1984 | ;; converting the inum to a double, which on a 64-bit would round making | |
1985 | ;; say inexact 2^58 appear equal to exact 2^58+1 | |
1986 | (pass-if (= (ash-flo 1.0 58) (ash 1 58))) | |
1987 | (pass-if (not (= (ash-flo 1.0 58) (1+ (ash 1 58))))) | |
1988 | (pass-if (not (= (ash-flo 1.0 58) (1- (ash 1 58))))) | |
1989 | (pass-if (= (ash 1 58) (ash-flo 1.0 58))) | |
1990 | (pass-if (not (= (1+ (ash 1 58)) (ash-flo 1.0 58)))) | |
1991 | (pass-if (not (= (1- (ash 1 58)) (ash-flo 1.0 58))))) | |
7c24e528 | 1992 | |
de142bea DH |
1993 | ;;; |
1994 | ;;; < | |
1995 | ;;; | |
1996 | ||
1997 | (with-test-prefix "<" | |
1998 | ||
8a1f4f98 | 1999 | (pass-if "documented?" |
cb18f2a8 | 2000 | (documented? <)) |
de142bea | 2001 | |
de142bea DH |
2002 | (with-test-prefix "(< 0 n)" |
2003 | ||
2004 | (pass-if "n = 0" | |
2005 | (not (< 0 0))) | |
2006 | ||
2007 | (pass-if "n = 0.0" | |
2008 | (not (< 0 0.0))) | |
2009 | ||
2010 | (pass-if "n = 1" | |
2011 | (< 0 1)) | |
2012 | ||
2013 | (pass-if "n = 1.0" | |
2014 | (< 0 1.0)) | |
2015 | ||
2016 | (pass-if "n = -1" | |
2017 | (not (< 0 -1))) | |
2018 | ||
2019 | (pass-if "n = -1.0" | |
2020 | (not (< 0 -1.0))) | |
2021 | ||
21e39e8f DH |
2022 | (pass-if "n = fixnum-max" |
2023 | (< 0 fixnum-max)) | |
2024 | ||
2025 | (pass-if "n = fixnum-max + 1" | |
2026 | (< 0 (+ fixnum-max 1))) | |
2027 | ||
2028 | (pass-if "n = fixnum-min" | |
2029 | (not (< 0 fixnum-min))) | |
de142bea | 2030 | |
21e39e8f DH |
2031 | (pass-if "n = fixnum-min - 1" |
2032 | (not (< 0 (- fixnum-min 1))))) | |
2033 | ||
de142bea DH |
2034 | (with-test-prefix "(< 0.0 n)" |
2035 | ||
2036 | (pass-if "n = 0" | |
2037 | (not (< 0.0 0))) | |
2038 | ||
2039 | (pass-if "n = 0.0" | |
2040 | (not (< 0.0 0.0))) | |
2041 | ||
2042 | (pass-if "n = 1" | |
2043 | (< 0.0 1)) | |
2044 | ||
2045 | (pass-if "n = 1.0" | |
2046 | (< 0.0 1.0)) | |
2047 | ||
2048 | (pass-if "n = -1" | |
2049 | (not (< 0.0 -1))) | |
2050 | ||
2051 | (pass-if "n = -1.0" | |
2052 | (not (< 0.0 -1.0))) | |
2053 | ||
21e39e8f DH |
2054 | (pass-if "n = fixnum-max" |
2055 | (< 0.0 fixnum-max)) | |
2056 | ||
2057 | (pass-if "n = fixnum-max + 1" | |
2058 | (< 0.0 (+ fixnum-max 1))) | |
de142bea | 2059 | |
21e39e8f DH |
2060 | (pass-if "n = fixnum-min" |
2061 | (not (< 0.0 fixnum-min))) | |
2062 | ||
2063 | (pass-if "n = fixnum-min - 1" | |
2064 | (not (< 0.0 (- fixnum-min 1))))) | |
2065 | ||
2066 | (with-test-prefix "(< 1 n)" | |
de142bea | 2067 | |
21e39e8f | 2068 | (pass-if "n = 0" |
de142bea DH |
2069 | (not (< 1 0))) |
2070 | ||
21e39e8f DH |
2071 | (pass-if "n = 0.0" |
2072 | (not (< 1 0.0))) | |
2073 | ||
2074 | (pass-if "n = 1" | |
2075 | (not (< 1 1))) | |
2076 | ||
de142bea | 2077 | (pass-if "n = 1.0" |
21e39e8f DH |
2078 | (not (< 1 1.0))) |
2079 | ||
2080 | (pass-if "n = -1" | |
2081 | (not (< 1 -1))) | |
2082 | ||
2083 | (pass-if "n = -1.0" | |
2084 | (not (< 1 -1.0))) | |
2085 | ||
2086 | (pass-if "n = fixnum-max" | |
2087 | (< 1 fixnum-max)) | |
2088 | ||
2089 | (pass-if "n = fixnum-max + 1" | |
2090 | (< 1 (+ fixnum-max 1))) | |
2091 | ||
2092 | (pass-if "n = fixnum-min" | |
2093 | (not (< 1 fixnum-min))) | |
2094 | ||
2095 | (pass-if "n = fixnum-min - 1" | |
2096 | (not (< 1 (- fixnum-min 1))))) | |
2097 | ||
2098 | (with-test-prefix "(< 1.0 n)" | |
2099 | ||
2100 | (pass-if "n = 0" | |
de142bea DH |
2101 | (not (< 1.0 0))) |
2102 | ||
21e39e8f DH |
2103 | (pass-if "n = 0.0" |
2104 | (not (< 1.0 0.0))) | |
2105 | ||
2106 | (pass-if "n = 1" | |
2107 | (not (< 1.0 1))) | |
2108 | ||
2109 | (pass-if "n = 1.0" | |
2110 | (not (< 1.0 1.0))) | |
2111 | ||
de142bea | 2112 | (pass-if "n = -1" |
21e39e8f DH |
2113 | (not (< 1.0 -1))) |
2114 | ||
2115 | (pass-if "n = -1.0" | |
2116 | (not (< 1.0 -1.0))) | |
2117 | ||
2118 | (pass-if "n = fixnum-max" | |
2119 | (< 1.0 fixnum-max)) | |
2120 | ||
2121 | (pass-if "n = fixnum-max + 1" | |
2122 | (< 1.0 (+ fixnum-max 1))) | |
2123 | ||
2124 | (pass-if "n = fixnum-min" | |
2125 | (not (< 1.0 fixnum-min))) | |
2126 | ||
2127 | (pass-if "n = fixnum-min - 1" | |
2128 | (not (< 1.0 (- fixnum-min 1))))) | |
2129 | ||
2130 | (with-test-prefix "(< -1 n)" | |
2131 | ||
2132 | (pass-if "n = 0" | |
de142bea DH |
2133 | (< -1 0)) |
2134 | ||
21e39e8f DH |
2135 | (pass-if "n = 0.0" |
2136 | (< -1 0.0)) | |
2137 | ||
2138 | (pass-if "n = 1" | |
2139 | (< -1 1)) | |
2140 | ||
2141 | (pass-if "n = 1.0" | |
2142 | (< -1 1.0)) | |
2143 | ||
2144 | (pass-if "n = -1" | |
2145 | (not (< -1 -1))) | |
2146 | ||
de142bea | 2147 | (pass-if "n = -1.0" |
21e39e8f DH |
2148 | (not (< -1 -1.0))) |
2149 | ||
2150 | (pass-if "n = fixnum-max" | |
2151 | (< -1 fixnum-max)) | |
2152 | ||
2153 | (pass-if "n = fixnum-max + 1" | |
2154 | (< -1 (+ fixnum-max 1))) | |
2155 | ||
2156 | (pass-if "n = fixnum-min" | |
2157 | (not (< -1 fixnum-min))) | |
2158 | ||
2159 | (pass-if "n = fixnum-min - 1" | |
2160 | (not (< -1 (- fixnum-min 1))))) | |
2161 | ||
2162 | (with-test-prefix "(< -1.0 n)" | |
2163 | ||
2164 | (pass-if "n = 0" | |
de142bea DH |
2165 | (< -1.0 0)) |
2166 | ||
21e39e8f DH |
2167 | (pass-if "n = 0.0" |
2168 | (< -1.0 0.0)) | |
2169 | ||
2170 | (pass-if "n = 1" | |
2171 | (< -1.0 1)) | |
2172 | ||
2173 | (pass-if "n = 1.0" | |
2174 | (< -1.0 1.0)) | |
2175 | ||
2176 | (pass-if "n = -1" | |
2177 | (not (< -1.0 -1))) | |
2178 | ||
2179 | (pass-if "n = -1.0" | |
2180 | (not (< -1.0 -1.0))) | |
2181 | ||
2182 | (pass-if "n = fixnum-max" | |
2183 | (< -1.0 fixnum-max)) | |
2184 | ||
2185 | (pass-if "n = fixnum-max + 1" | |
2186 | (< -1.0 (+ fixnum-max 1))) | |
de142bea | 2187 | |
21e39e8f DH |
2188 | (pass-if "n = fixnum-min" |
2189 | (not (< -1.0 fixnum-min))) | |
2190 | ||
2191 | (pass-if "n = fixnum-min - 1" | |
2192 | (not (< -1.0 (- fixnum-min 1))))) | |
2193 | ||
2194 | (with-test-prefix "(< fixnum-max n)" | |
2195 | ||
2196 | (pass-if "n = 0" | |
2197 | (not (< fixnum-max 0))) | |
2198 | ||
2199 | (pass-if "n = 0.0" | |
2200 | (not (< fixnum-max 0.0))) | |
de142bea DH |
2201 | |
2202 | (pass-if "n = 1" | |
21e39e8f | 2203 | (not (< fixnum-max 1))) |
de142bea DH |
2204 | |
2205 | (pass-if "n = 1.0" | |
21e39e8f | 2206 | (not (< fixnum-max 1.0))) |
de142bea DH |
2207 | |
2208 | (pass-if "n = -1" | |
21e39e8f | 2209 | (not (< fixnum-max -1))) |
de142bea DH |
2210 | |
2211 | (pass-if "n = -1.0" | |
21e39e8f | 2212 | (not (< fixnum-max -1.0))) |
de142bea | 2213 | |
21e39e8f DH |
2214 | (pass-if "n = fixnum-max" |
2215 | (not (< fixnum-max fixnum-max))) | |
de142bea | 2216 | |
21e39e8f DH |
2217 | (pass-if "n = fixnum-max + 1" |
2218 | (< fixnum-max (+ fixnum-max 1))) | |
2219 | ||
2220 | (pass-if "n = fixnum-min" | |
2221 | (not (< fixnum-max fixnum-min))) | |
2222 | ||
2223 | (pass-if "n = fixnum-min - 1" | |
2224 | (not (< fixnum-max (- fixnum-min 1))))) | |
2225 | ||
2226 | (with-test-prefix "(< (+ fixnum-max 1) n)" | |
2227 | ||
2228 | (pass-if "n = 0" | |
2229 | (not (< (+ fixnum-max 1) 0))) | |
2230 | ||
2231 | (pass-if "n = 0.0" | |
2232 | (not (< (+ fixnum-max 1) 0.0))) | |
de142bea DH |
2233 | |
2234 | (pass-if "n = 1" | |
21e39e8f | 2235 | (not (< (+ fixnum-max 1) 1))) |
de142bea DH |
2236 | |
2237 | (pass-if "n = 1.0" | |
21e39e8f | 2238 | (not (< (+ fixnum-max 1) 1.0))) |
de142bea DH |
2239 | |
2240 | (pass-if "n = -1" | |
21e39e8f | 2241 | (not (< (+ fixnum-max 1) -1))) |
de142bea DH |
2242 | |
2243 | (pass-if "n = -1.0" | |
21e39e8f | 2244 | (not (< (+ fixnum-max 1) -1.0))) |
de142bea | 2245 | |
21e39e8f DH |
2246 | (pass-if "n = fixnum-max" |
2247 | (not (< (+ fixnum-max 1) fixnum-max))) | |
de142bea | 2248 | |
21e39e8f DH |
2249 | (pass-if "n = fixnum-max + 1" |
2250 | (not (< (+ fixnum-max 1) (+ fixnum-max 1)))) | |
de142bea | 2251 | |
21e39e8f DH |
2252 | (pass-if "n = fixnum-min" |
2253 | (not (< (+ fixnum-max 1) fixnum-min))) | |
2254 | ||
2255 | (pass-if "n = fixnum-min - 1" | |
2256 | (not (< (+ fixnum-max 1) (- fixnum-min 1))))) | |
2257 | ||
2258 | (with-test-prefix "(< fixnum-min n)" | |
2259 | ||
2260 | (pass-if "n = 0" | |
2261 | (< fixnum-min 0)) | |
2262 | ||
2263 | (pass-if "n = 0.0" | |
2264 | (< fixnum-min 0.0)) | |
de142bea DH |
2265 | |
2266 | (pass-if "n = 1" | |
21e39e8f | 2267 | (< fixnum-min 1)) |
de142bea DH |
2268 | |
2269 | (pass-if "n = 1.0" | |
21e39e8f | 2270 | (< fixnum-min 1.0)) |
de142bea DH |
2271 | |
2272 | (pass-if "n = -1" | |
21e39e8f | 2273 | (< fixnum-min -1)) |
de142bea DH |
2274 | |
2275 | (pass-if "n = -1.0" | |
21e39e8f | 2276 | (< fixnum-min -1.0)) |
de142bea | 2277 | |
21e39e8f DH |
2278 | (pass-if "n = fixnum-max" |
2279 | (< fixnum-min fixnum-max)) | |
2280 | ||
2281 | (pass-if "n = fixnum-max + 1" | |
2282 | (< fixnum-min (+ fixnum-max 1))) | |
de142bea | 2283 | |
21e39e8f DH |
2284 | (pass-if "n = fixnum-min" |
2285 | (not (< fixnum-min fixnum-min))) | |
de142bea | 2286 | |
21e39e8f DH |
2287 | (pass-if "n = fixnum-min - 1" |
2288 | (not (< fixnum-min (- fixnum-min 1))))) | |
2289 | ||
2290 | (with-test-prefix "(< (- fixnum-min 1) n)" | |
2291 | ||
2292 | (pass-if "n = 0" | |
2293 | (< (- fixnum-min 1) 0)) | |
2294 | ||
2295 | (pass-if "n = 0.0" | |
2296 | (< (- fixnum-min 1) 0.0)) | |
2297 | ||
2298 | (pass-if "n = 1" | |
2299 | (< (- fixnum-min 1) 1)) | |
2300 | ||
2301 | (pass-if "n = 1.0" | |
2302 | (< (- fixnum-min 1) 1.0)) | |
de142bea DH |
2303 | |
2304 | (pass-if "n = -1" | |
21e39e8f | 2305 | (< (- fixnum-min 1) -1)) |
de142bea DH |
2306 | |
2307 | (pass-if "n = -1.0" | |
21e39e8f DH |
2308 | (< (- fixnum-min 1) -1.0)) |
2309 | ||
2310 | (pass-if "n = fixnum-max" | |
2311 | (< (- fixnum-min 1) fixnum-max)) | |
2312 | ||
2313 | (pass-if "n = fixnum-max + 1" | |
2314 | (< (- fixnum-min 1) (+ fixnum-max 1))) | |
2315 | ||
2316 | (pass-if "n = fixnum-min" | |
2317 | (< (- fixnum-min 1) fixnum-min)) | |
2318 | ||
2319 | (pass-if "n = fixnum-min - 1" | |
2cfcaed5 KR |
2320 | (not (< (- fixnum-min 1) (- fixnum-min 1))))) |
2321 | ||
adda36ed KR |
2322 | (pass-if (< (ash 1 256) +inf.0)) |
2323 | (pass-if (not (< +inf.0 (ash 1 256)))) | |
2324 | (pass-if (not (< (ash 1 256) -inf.0))) | |
2325 | (pass-if (< -inf.0 (ash 1 256))) | |
2326 | ||
2327 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating Inf as 2^1024, make | |
2328 | ;; sure we've avoided that | |
2329 | (pass-if (< (1- (ash 1 1024)) +inf.0)) | |
2330 | (pass-if (< (ash 1 1024) +inf.0)) | |
2331 | (pass-if (< (1+ (ash 1 1024)) +inf.0)) | |
2332 | (pass-if (not (< +inf.0 (1- (ash 1 1024))))) | |
2333 | (pass-if (not (< +inf.0 (ash 1 1024)))) | |
2334 | (pass-if (not (< +inf.0 (1+ (ash 1 1024))))) | |
2335 | (pass-if (< -inf.0 (- (1- (ash 1 1024))))) | |
2336 | (pass-if (< -inf.0 (- (ash 1 1024)))) | |
2337 | (pass-if (< -inf.0 (- (1+ (ash 1 1024))))) | |
2338 | (pass-if (not (< (- (1- (ash 1 1024))) -inf.0))) | |
2339 | (pass-if (not (< (- (ash 1 1024)) -inf.0))) | |
2340 | (pass-if (not (< (- (1+ (ash 1 1024))) -inf.0))) | |
2341 | ||
2cfcaed5 KR |
2342 | (pass-if (not (< +nan.0 +nan.0))) |
2343 | (pass-if (not (< 0 +nan.0))) | |
2344 | (pass-if (not (< +nan.0 0))) | |
2345 | (pass-if (not (< 1 +nan.0))) | |
2346 | (pass-if (not (< +nan.0 1))) | |
2347 | (pass-if (not (< -1 +nan.0))) | |
2348 | (pass-if (not (< +nan.0 -1))) | |
2349 | ||
2350 | (pass-if (not (< (ash 1 256) +nan.0))) | |
2351 | (pass-if (not (< +nan.0 (ash 1 256)))) | |
2352 | (pass-if (not (< (- (ash 1 256)) +nan.0))) | |
2353 | (pass-if (not (< +nan.0 (- (ash 1 256))))) | |
2354 | ||
2355 | (pass-if (not (< (ash 1 8192) +nan.0))) | |
2356 | (pass-if (not (< +nan.0 (ash 1 8192)))) | |
2357 | (pass-if (not (< (- (ash 1 8192)) +nan.0))) | |
2358 | (pass-if (not (< +nan.0 (- (ash 1 8192))))) | |
2359 | ||
2360 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make | |
2361 | ;; sure we've avoided that | |
2362 | (pass-if (not (< (ash 3 1023) +nan.0))) | |
2363 | (pass-if (not (< (1+ (ash 3 1023)) +nan.0))) | |
2364 | (pass-if (not (< (1- (ash 3 1023)) +nan.0))) | |
2365 | (pass-if (not (< +nan.0 (ash 3 1023)))) | |
2366 | (pass-if (not (< +nan.0 (1+ (ash 3 1023))))) | |
fe89421e KR |
2367 | (pass-if (not (< +nan.0 (1- (ash 3 1023))))) |
2368 | ||
2369 | (with-test-prefix "inum/frac" | |
2370 | (pass-if (< 2 9/4)) | |
2371 | (pass-if (< -2 9/4)) | |
2372 | (pass-if (< -2 7/4)) | |
2373 | (pass-if (< -2 -7/4)) | |
2374 | (pass-if (eq? #f (< 2 7/4))) | |
2375 | (pass-if (eq? #f (< 2 -7/4))) | |
2376 | (pass-if (eq? #f (< 2 -9/4))) | |
2377 | (pass-if (eq? #f (< -2 -9/4)))) | |
2378 | ||
2379 | (with-test-prefix "bignum/frac" | |
2380 | (let ((x (ash 1 2048))) | |
2381 | (pass-if (< x (* 4/3 x))) | |
2382 | (pass-if (< (- x) (* 4/3 x))) | |
2383 | (pass-if (< (- x) (* 2/3 x))) | |
2384 | (pass-if (< (- x) (* -2/3 x))) | |
2385 | (pass-if (eq? #f (< x (* 2/3 x)))) | |
2386 | (pass-if (eq? #f (< x (* -2/3 x)))) | |
2387 | (pass-if (eq? #f (< x (* -4/3 x)))) | |
2388 | (pass-if (eq? #f (< (- x) (* -4/3 x)))))) | |
2389 | ||
2390 | (with-test-prefix "flonum/frac" | |
2391 | (pass-if (< 0.75 4/3)) | |
2392 | (pass-if (< -0.75 4/3)) | |
2393 | (pass-if (< -0.75 2/3)) | |
2394 | (pass-if (< -0.75 -2/3)) | |
2395 | (pass-if (eq? #f (< 0.75 2/3))) | |
2396 | (pass-if (eq? #f (< 0.75 -2/3))) | |
2397 | (pass-if (eq? #f (< 0.75 -4/3))) | |
2398 | (pass-if (eq? #f (< -0.75 -4/3))) | |
2399 | ||
2400 | (pass-if (< -inf.0 4/3)) | |
2401 | (pass-if (< -inf.0 -4/3)) | |
2402 | (pass-if (eq? #f (< +inf.0 4/3))) | |
2403 | (pass-if (eq? #f (< +inf.0 -4/3))) | |
2404 | ||
2405 | (pass-if (eq? #f (< +nan.0 4/3))) | |
2406 | (pass-if (eq? #f (< +nan.0 -4/3)))) | |
2407 | ||
2408 | (with-test-prefix "frac/inum" | |
2409 | (pass-if (< 7/4 2)) | |
2410 | (pass-if (< -7/4 2)) | |
2411 | (pass-if (< -9/4 2)) | |
2412 | (pass-if (< -9/4 -2)) | |
2413 | (pass-if (eq? #f (< 9/4 2))) | |
2414 | (pass-if (eq? #f (< 9/4 -2))) | |
2415 | (pass-if (eq? #f (< 7/4 -2))) | |
2416 | (pass-if (eq? #f (< -7/4 -2)))) | |
2417 | ||
2418 | (with-test-prefix "frac/bignum" | |
2419 | (let ((x (ash 1 2048))) | |
2420 | (pass-if (< (* 2/3 x) x)) | |
2421 | (pass-if (< (* -2/3 x) x)) | |
2422 | (pass-if (< (* -4/3 x) x)) | |
2423 | (pass-if (< (* -4/3 x) (- x))) | |
2424 | (pass-if (eq? #f (< (* 4/3 x) x))) | |
2425 | (pass-if (eq? #f (< (* 4/3 x) (- x)))) | |
2426 | (pass-if (eq? #f (< (* 2/3 x) (- x)))) | |
2427 | (pass-if (eq? #f (< (* -2/3 x) (- x)))))) | |
2428 | ||
2429 | (with-test-prefix "frac/flonum" | |
2430 | (pass-if (< 2/3 0.75)) | |
2431 | (pass-if (< -2/3 0.75)) | |
2432 | (pass-if (< -4/3 0.75)) | |
2433 | (pass-if (< -4/3 -0.75)) | |
2434 | (pass-if (eq? #f (< 4/3 0.75))) | |
2435 | (pass-if (eq? #f (< 4/3 -0.75))) | |
2436 | (pass-if (eq? #f (< 2/3 -0.75))) | |
2437 | (pass-if (eq? #f (< -2/3 -0.75))) | |
2438 | ||
2439 | (pass-if (< 4/3 +inf.0)) | |
2440 | (pass-if (< -4/3 +inf.0)) | |
2441 | (pass-if (eq? #f (< 4/3 -inf.0))) | |
2442 | (pass-if (eq? #f (< -4/3 -inf.0))) | |
2443 | ||
2444 | (pass-if (eq? #f (< 4/3 +nan.0))) | |
2445 | (pass-if (eq? #f (< -4/3 +nan.0)))) | |
2446 | ||
2447 | (with-test-prefix "frac/frac" | |
2448 | (pass-if (< 2/3 6/7)) | |
2449 | (pass-if (< -2/3 6/7)) | |
2450 | (pass-if (< -4/3 6/7)) | |
2451 | (pass-if (< -4/3 -6/7)) | |
2452 | (pass-if (eq? #f (< 4/3 6/7))) | |
2453 | (pass-if (eq? #f (< 4/3 -6/7))) | |
2454 | (pass-if (eq? #f (< 2/3 -6/7))) | |
2455 | (pass-if (eq? #f (< -2/3 -6/7))))) | |
f29b3454 DH |
2456 | |
2457 | ;;; | |
2458 | ;;; > | |
2459 | ;;; | |
2460 | ||
7c24e528 RB |
2461 | ;; currently not tested -- implementation is trivial |
2462 | ;; (> x y) is implemented as (< y x) | |
2463 | ;; FIXME: tests should probably be added in case we change implementation. | |
2464 | ||
f29b3454 DH |
2465 | ;;; |
2466 | ;;; <= | |
2467 | ;;; | |
2468 | ||
7c24e528 RB |
2469 | ;; currently not tested -- implementation is trivial |
2470 | ;; (<= x y) is implemented as (not (< y x)) | |
2471 | ;; FIXME: tests should probably be added in case we change implementation. | |
2472 | ||
f29b3454 DH |
2473 | ;;; |
2474 | ;;; >= | |
2475 | ;;; | |
2476 | ||
7c24e528 RB |
2477 | ;; currently not tested -- implementation is trivial |
2478 | ;; (>= x y) is implemented as (not (< x y)) | |
2479 | ;; FIXME: tests should probably be added in case we change implementation. | |
2480 | ||
f29b3454 DH |
2481 | ;;; |
2482 | ;;; zero? | |
2483 | ;;; | |
2484 | ||
7c24e528 | 2485 | (with-test-prefix "zero?" |
2519490c | 2486 | (pass-if (documented? zero?)) |
c7218482 MW |
2487 | |
2488 | (pass-if (zero? 0)) | |
2489 | (pass-if (zero? 0.0)) | |
2490 | (pass-if (zero? -0.0)) | |
2491 | ||
2492 | (pass-if (zero? 0.0+0.0i)) | |
2493 | (pass-if (zero? 0.0-0.0i)) | |
2494 | (pass-if (zero? 0.0+0.0i)) | |
2495 | (pass-if (zero? -0.0-0.0i)) | |
2496 | ||
2497 | (pass-if (not (zero? 7))) | |
4d332f19 | 2498 | (pass-if (not (zero? -7))) |
c7218482 MW |
2499 | (pass-if (not (zero? 1/7))) |
2500 | (pass-if (not (zero? -inf.0))) | |
2501 | (pass-if (not (zero? +inf.0))) | |
2502 | (pass-if (not (zero? +nan.0))) | |
4d332f19 DH |
2503 | (pass-if (not (zero? (+ 1 fixnum-max)))) |
2504 | (pass-if (not (zero? (- 1 fixnum-min)))) | |
2505 | (pass-if (not (zero? 1.3))) | |
c7218482 MW |
2506 | (pass-if (not (zero? 3.1+4.2i))) |
2507 | (pass-if (not (zero? 1.0+0.0i))) | |
2508 | (pass-if (not (zero? 0.0-1.0i)))) | |
7c24e528 | 2509 | |
f29b3454 DH |
2510 | ;;; |
2511 | ;;; positive? | |
2512 | ;;; | |
2513 | ||
7c24e528 | 2514 | (with-test-prefix "positive?" |
2519490c | 2515 | (pass-if (documented? positive?)) |
7c24e528 RB |
2516 | (pass-if (positive? 1)) |
2517 | (pass-if (positive? (+ fixnum-max 1))) | |
2518 | (pass-if (positive? 1.3)) | |
4d332f19 DH |
2519 | (pass-if (not (positive? 0))) |
2520 | (pass-if (not (positive? -1))) | |
2521 | (pass-if (not (positive? (- fixnum-min 1)))) | |
2522 | (pass-if (not (positive? -1.3)))) | |
7c24e528 | 2523 | |
f29b3454 DH |
2524 | ;;; |
2525 | ;;; negative? | |
2526 | ;;; | |
2527 | ||
7c24e528 | 2528 | (with-test-prefix "negative?" |
2519490c | 2529 | (pass-if (documented? negative?)) |
4d332f19 DH |
2530 | (pass-if (not (negative? 1))) |
2531 | (pass-if (not (negative? (+ fixnum-max 1)))) | |
2532 | (pass-if (not (negative? 1.3))) | |
2533 | (pass-if (not (negative? 0))) | |
7c24e528 RB |
2534 | (pass-if (negative? -1)) |
2535 | (pass-if (negative? (- fixnum-min 1))) | |
2536 | (pass-if (negative? -1.3))) | |
2537 | ||
f29b3454 DH |
2538 | ;;; |
2539 | ;;; max | |
2540 | ;;; | |
2541 | ||
adda36ed | 2542 | (with-test-prefix "max" |
593a4c2f KR |
2543 | (pass-if-exception "no args" exception:wrong-num-args |
2544 | (max)) | |
2545 | ||
2546 | (pass-if-exception "one complex" exception:wrong-type-arg | |
2547 | (max 1+i)) | |
2548 | ||
2549 | (pass-if-exception "inum/complex" exception:wrong-type-arg | |
2550 | (max 123 1+i)) | |
2551 | (pass-if-exception "big/complex" exception:wrong-type-arg | |
2552 | (max 9999999999999999999999999999999999999999 1+i)) | |
2553 | (pass-if-exception "real/complex" exception:wrong-type-arg | |
2554 | (max 123.0 1+i)) | |
2555 | (pass-if-exception "frac/complex" exception:wrong-type-arg | |
2556 | (max 123/456 1+i)) | |
2557 | ||
2558 | (pass-if-exception "complex/inum" exception:wrong-type-arg | |
2559 | (max 1+i 123)) | |
2560 | (pass-if-exception "complex/big" exception:wrong-type-arg | |
2561 | (max 1+i 9999999999999999999999999999999999999999)) | |
2562 | (pass-if-exception "complex/real" exception:wrong-type-arg | |
2563 | (max 1+i 123.0)) | |
2564 | (pass-if-exception "complex/frac" exception:wrong-type-arg | |
2565 | (max 1+i 123/456)) | |
2566 | ||
adda36ed KR |
2567 | (let ((big*2 (* fixnum-max 2)) |
2568 | (big*3 (* fixnum-max 3)) | |
2569 | (big*4 (* fixnum-max 4)) | |
2570 | (big*5 (* fixnum-max 5))) | |
501da403 | 2571 | |
2530518e | 2572 | (with-test-prefix "inum / frac" |
2e274311 MW |
2573 | (pass-if (eqv? 3 (max 3 5/2))) |
2574 | (pass-if (eqv? 5/2 (max 2 5/2)))) | |
2530518e KR |
2575 | |
2576 | (with-test-prefix "frac / inum" | |
2e274311 MW |
2577 | (pass-if (eqv? 3 (max 5/2 3))) |
2578 | (pass-if (eqv? 5/2 (max 5/2 2)))) | |
2579 | ||
2580 | (with-test-prefix "infinities and NaNs" | |
2581 | ;; +inf.0 beats everything else, including NaNs | |
2582 | (pass-if (eqv? +inf.0 (max +inf.0 123 ))) | |
2583 | (pass-if (eqv? +inf.0 (max 123 +inf.0 ))) | |
2584 | (pass-if (eqv? +inf.0 (max +inf.0 -123.3 ))) | |
2585 | (pass-if (eqv? +inf.0 (max -123.3 +inf.0 ))) | |
2586 | (pass-if (eqv? +inf.0 (max +inf.0 -7/2 ))) | |
2587 | (pass-if (eqv? +inf.0 (max -7/2 +inf.0 ))) | |
2588 | (pass-if (eqv? +inf.0 (max +inf.0 -1e20 ))) | |
2589 | (pass-if (eqv? +inf.0 (max -1e20 +inf.0 ))) | |
2590 | (pass-if (eqv? +inf.0 (max +inf.0 (- big*2)))) | |
2591 | (pass-if (eqv? +inf.0 (max (- big*2) +inf.0 ))) | |
2592 | (pass-if (eqv? +inf.0 (max +inf.0 +inf.0 ))) | |
2593 | (pass-if (eqv? +inf.0 (max +inf.0 +inf.0 ))) | |
2594 | (pass-if (eqv? +inf.0 (max +inf.0 +nan.0 ))) | |
2595 | (pass-if (eqv? +inf.0 (max +nan.0 +inf.0 ))) | |
2596 | (pass-if (eqv? +inf.0 (max +inf.0 +inf.0 ))) | |
2597 | ||
2598 | ;; NaNs beat everything except +inf.0 | |
2599 | (pass-if (real-nan? (max +nan.0 123 ))) | |
2600 | (pass-if (real-nan? (max 123 +nan.0 ))) | |
2601 | (pass-if (real-nan? (max +nan.0 123.3 ))) | |
2602 | (pass-if (real-nan? (max 123.3 +nan.0 ))) | |
2603 | (pass-if (real-nan? (max +nan.0 -7/2 ))) | |
2604 | (pass-if (real-nan? (max -7/2 +nan.0 ))) | |
2605 | (pass-if (real-nan? (max +nan.0 -1e20 ))) | |
2606 | (pass-if (real-nan? (max -1e20 +nan.0 ))) | |
2607 | (pass-if (real-nan? (max +nan.0 (- big*2)))) | |
2608 | (pass-if (real-nan? (max (- big*2) +nan.0 ))) | |
2609 | (pass-if (real-nan? (max +nan.0 -inf.0 ))) | |
2610 | (pass-if (real-nan? (max -inf.0 +nan.0 ))) | |
2611 | (pass-if (real-nan? (max +nan.0 +nan.0 ))) | |
2612 | ||
2613 | ;; -inf.0 always loses, except against itself | |
2614 | (pass-if (eqv? -inf.0 (max -inf.0 -inf.0 ))) | |
2615 | (pass-if (eqv? -123.0 (max -inf.0 -123 ))) | |
2616 | (pass-if (eqv? -123.0 (max -123 -inf.0 ))) | |
2617 | (pass-if (eqv? -123.3 (max -inf.0 -123.3 ))) | |
2618 | (pass-if (eqv? -123.3 (max -123.3 -inf.0 ))) | |
2619 | (pass-if (eqv? -3.5 (max -inf.0 -7/2 ))) | |
2620 | (pass-if (eqv? -3.5 (max -7/2 -inf.0 ))) | |
2621 | (pass-if (eqv? -1.0e20 (max -inf.0 -1e20 ))) | |
2622 | (pass-if (eqv? -1.0e20 (max -1e20 -inf.0 ))) | |
2623 | (pass-if (eqv? (exact->inexact (- big*2)) | |
2624 | (max -inf.0 (- big*2)))) | |
2625 | (pass-if (eqv? (exact->inexact (- big*2)) | |
2626 | (max (- big*2) -inf.0 )))) | |
2627 | ||
2628 | (with-test-prefix "signed zeroes" | |
2629 | (pass-if (eqv? 0.0 (max 0.0 0.0))) | |
2630 | (pass-if (eqv? 0.0 (max 0.0 -0.0))) | |
2631 | (pass-if (eqv? 0.0 (max -0.0 0.0))) | |
2632 | (pass-if (eqv? -0.0 (max -0.0 -0.0))) | |
2633 | (pass-if (eqv? 0.0 (max -0.0 0 ))) | |
2634 | (pass-if (eqv? 0.0 (max 0.0 0 ))) | |
2635 | (pass-if (eqv? 0.0 (max 0 -0.0))) | |
2636 | (pass-if (eqv? 0.0 (max 0 0.0))) | |
2637 | (pass-if (eqv? 0 (min 0 0 )))) | |
23d77957 | 2638 | |
2530518e | 2639 | (with-test-prefix "big / frac" |
2e274311 MW |
2640 | (pass-if (eqv? big*2 (max big*2 5/2))) |
2641 | (pass-if (eqv? 5/2 (max (- big*2) 5/2)))) | |
2530518e KR |
2642 | |
2643 | (with-test-prefix "frac / big" | |
2e274311 MW |
2644 | (pass-if (eqv? big*2 (max 5/2 big*2))) |
2645 | (pass-if (eqv? 5/2 (max 5/2 (- big*2))))) | |
2530518e | 2646 | |
23d77957 | 2647 | (with-test-prefix "big / real" |
55a8b708 | 2648 | (pass-if (real-nan? (max big*5 +nan.0))) |
23d72566 KR |
2649 | (pass-if (eqv? (exact->inexact big*5) (max big*5 -inf.0))) |
2650 | (pass-if (eqv? (exact->inexact big*5) (max big*5 1.0))) | |
2651 | (pass-if (eqv? +inf.0 (max big*5 +inf.0))) | |
2652 | (pass-if (eqv? 1.0 (max (- big*5) 1.0)))) | |
23d77957 KR |
2653 | |
2654 | (with-test-prefix "real / big" | |
55a8b708 | 2655 | (pass-if (real-nan? (max +nan.0 big*5))) |
23d72566 KR |
2656 | (pass-if (eqv? (exact->inexact big*5) (max -inf.0 big*5))) |
2657 | (pass-if (eqv? (exact->inexact big*5) (max 1.0 big*5))) | |
2658 | (pass-if (eqv? +inf.0 (max +inf.0 big*5))) | |
2659 | (pass-if (eqv? 1.0 (max 1.0 (- big*5))))) | |
23d77957 | 2660 | |
2530518e | 2661 | (with-test-prefix "frac / frac" |
2e274311 MW |
2662 | (pass-if (eqv? 2/3 (max 1/2 2/3))) |
2663 | (pass-if (eqv? 2/3 (max 2/3 1/2))) | |
2664 | (pass-if (eqv? -1/2 (max -1/2 -2/3))) | |
2665 | (pass-if (eqv? -1/2 (max -2/3 -1/2)))) | |
2530518e | 2666 | |
23d77957 | 2667 | (with-test-prefix "real / real" |
55a8b708 MW |
2668 | (pass-if (real-nan? (max 123.0 +nan.0))) |
2669 | (pass-if (real-nan? (max +nan.0 123.0))) | |
2670 | (pass-if (real-nan? (max +nan.0 +nan.0))) | |
2e274311 MW |
2671 | (pass-if (eqv? 456.0 (max 123.0 456.0))) |
2672 | (pass-if (eqv? 456.0 (max 456.0 123.0))))) | |
adda36ed KR |
2673 | |
2674 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating Inf as 2^1024, make | |
2675 | ;; sure we've avoided that | |
2676 | (for-each (lambda (b) | |
2677 | (pass-if (list b +inf.0) | |
2e274311 | 2678 | (eqv? +inf.0 (max b +inf.0))) |
adda36ed | 2679 | (pass-if (list +inf.0 b) |
2e274311 | 2680 | (eqv? +inf.0 (max b +inf.0))) |
adda36ed | 2681 | (pass-if (list b -inf.0) |
2e274311 | 2682 | (eqv? (exact->inexact b) (max b -inf.0))) |
adda36ed | 2683 | (pass-if (list -inf.0 b) |
2e274311 | 2684 | (eqv? (exact->inexact b) (max b -inf.0)))) |
adda36ed KR |
2685 | (list (1- (ash 1 1024)) |
2686 | (ash 1 1024) | |
2687 | (1+ (ash 1 1024)) | |
2688 | (- (1- (ash 1 1024))) | |
2689 | (- (ash 1 1024)) | |
501da403 KR |
2690 | (- (1+ (ash 1 1024))))) |
2691 | ||
2692 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make | |
2693 | ;; sure we've avoided that | |
55a8b708 MW |
2694 | (pass-if (real-nan? (max (ash 1 2048) +nan.0))) |
2695 | (pass-if (real-nan? (max +nan.0 (ash 1 2048))))) | |
adda36ed | 2696 | |
f29b3454 DH |
2697 | ;;; |
2698 | ;;; min | |
2699 | ;;; | |
2700 | ||
7c24e528 RB |
2701 | ;; FIXME: unfinished... |
2702 | ||
2703 | (with-test-prefix "min" | |
593a4c2f KR |
2704 | (pass-if-exception "no args" exception:wrong-num-args |
2705 | (min)) | |
2706 | ||
2707 | (pass-if-exception "one complex" exception:wrong-type-arg | |
2708 | (min 1+i)) | |
2709 | ||
2710 | (pass-if-exception "inum/complex" exception:wrong-type-arg | |
2711 | (min 123 1+i)) | |
2712 | (pass-if-exception "big/complex" exception:wrong-type-arg | |
2713 | (min 9999999999999999999999999999999999999999 1+i)) | |
2714 | (pass-if-exception "real/complex" exception:wrong-type-arg | |
2715 | (min 123.0 1+i)) | |
2716 | (pass-if-exception "frac/complex" exception:wrong-type-arg | |
2717 | (min 123/456 1+i)) | |
2718 | ||
2719 | (pass-if-exception "complex/inum" exception:wrong-type-arg | |
2720 | (min 1+i 123)) | |
2721 | (pass-if-exception "complex/big" exception:wrong-type-arg | |
2722 | (min 1+i 9999999999999999999999999999999999999999)) | |
2723 | (pass-if-exception "complex/real" exception:wrong-type-arg | |
2724 | (min 1+i 123.0)) | |
2725 | (pass-if-exception "complex/frac" exception:wrong-type-arg | |
2726 | (min 1+i 123/456)) | |
2727 | ||
7c24e528 RB |
2728 | (let ((big*2 (* fixnum-max 2)) |
2729 | (big*3 (* fixnum-max 3)) | |
2730 | (big*4 (* fixnum-max 4)) | |
2731 | (big*5 (* fixnum-max 5))) | |
23d77957 | 2732 | |
d389e966 | 2733 | (pass-if (documented? min)) |
2e274311 MW |
2734 | (pass-if (eqv? 1 (min 7 3 1 5))) |
2735 | (pass-if (eqv? 1 (min 1 7 3 5))) | |
2736 | (pass-if (eqv? 1 (min 7 3 5 1))) | |
2737 | (pass-if (eqv? -7 (min 2 3 4 -2 5 -7 1 -1 4 2))) | |
2738 | (pass-if (eqv? -7 (min -7 2 3 4 -2 5 1 -1 4 2))) | |
2739 | (pass-if (eqv? -7 (min 2 3 4 -2 5 1 -1 4 2 -7))) | |
2740 | (pass-if (eqv? big*2 (min big*3 big*5 big*2 big*4))) | |
2741 | (pass-if (eqv? big*2 (min big*2 big*3 big*5 big*4))) | |
2742 | (pass-if (eqv? big*2 (min big*3 big*5 big*4 big*2))) | |
7c24e528 | 2743 | (pass-if |
2e274311 | 2744 | (eqv? (- fixnum-min 1) (min 2 4 (- fixnum-min 1) 3 (* 2 fixnum-max)))) |
7c24e528 | 2745 | (pass-if |
2e274311 | 2746 | (eqv? (- fixnum-min 1) (min (- fixnum-min 1) 2 4 3 (* 2 fixnum-max)))) |
7c24e528 | 2747 | (pass-if |
2e274311 | 2748 | (eqv? (- fixnum-min 1) (min 2 4 3 (* 2 fixnum-max) (- fixnum-min 1)))) |
23d77957 | 2749 | |
2530518e | 2750 | (with-test-prefix "inum / frac" |
2e274311 MW |
2751 | (pass-if (eqv? 5/2 (min 3 5/2))) |
2752 | (pass-if (eqv? 2 (min 2 5/2)))) | |
2530518e KR |
2753 | |
2754 | (with-test-prefix "frac / inum" | |
2e274311 MW |
2755 | (pass-if (eqv? 5/2 (min 5/2 3))) |
2756 | (pass-if (eqv? 2 (min 5/2 2)))) | |
2757 | ||
2758 | (with-test-prefix "infinities and NaNs" | |
2759 | ;; -inf.0 beats everything else, including NaNs | |
2760 | (pass-if (eqv? -inf.0 (min -inf.0 123 ))) | |
2761 | (pass-if (eqv? -inf.0 (min 123 -inf.0 ))) | |
2762 | (pass-if (eqv? -inf.0 (min -inf.0 -123.3 ))) | |
2763 | (pass-if (eqv? -inf.0 (min -123.3 -inf.0 ))) | |
2764 | (pass-if (eqv? -inf.0 (min -inf.0 -7/2 ))) | |
2765 | (pass-if (eqv? -inf.0 (min -7/2 -inf.0 ))) | |
2766 | (pass-if (eqv? -inf.0 (min -inf.0 -1e20 ))) | |
2767 | (pass-if (eqv? -inf.0 (min -1e20 -inf.0 ))) | |
2768 | (pass-if (eqv? -inf.0 (min -inf.0 (- big*2)))) | |
2769 | (pass-if (eqv? -inf.0 (min (- big*2) -inf.0 ))) | |
2770 | (pass-if (eqv? -inf.0 (min -inf.0 +inf.0 ))) | |
2771 | (pass-if (eqv? -inf.0 (min +inf.0 -inf.0 ))) | |
2772 | (pass-if (eqv? -inf.0 (min -inf.0 +nan.0 ))) | |
2773 | (pass-if (eqv? -inf.0 (min +nan.0 -inf.0 ))) | |
2774 | (pass-if (eqv? -inf.0 (min -inf.0 -inf.0 ))) | |
2775 | ||
2776 | ;; NaNs beat everything except -inf.0 | |
2777 | (pass-if (real-nan? (min +nan.0 123 ))) | |
2778 | (pass-if (real-nan? (min 123 +nan.0 ))) | |
2779 | (pass-if (real-nan? (min +nan.0 123.3 ))) | |
2780 | (pass-if (real-nan? (min 123.3 +nan.0 ))) | |
2781 | (pass-if (real-nan? (min +nan.0 -7/2 ))) | |
2782 | (pass-if (real-nan? (min -7/2 +nan.0 ))) | |
2783 | (pass-if (real-nan? (min +nan.0 -1e20 ))) | |
2784 | (pass-if (real-nan? (min -1e20 +nan.0 ))) | |
2785 | (pass-if (real-nan? (min +nan.0 (- big*2)))) | |
2786 | (pass-if (real-nan? (min (- big*2) +nan.0 ))) | |
2787 | (pass-if (real-nan? (min +nan.0 +inf.0 ))) | |
2788 | (pass-if (real-nan? (min +inf.0 +nan.0 ))) | |
2789 | (pass-if (real-nan? (min +nan.0 +nan.0 ))) | |
2790 | ||
2791 | ;; +inf.0 always loses, except against itself | |
2792 | (pass-if (eqv? +inf.0 (min +inf.0 +inf.0 ))) | |
2793 | (pass-if (eqv? -123.0 (min +inf.0 -123 ))) | |
2794 | (pass-if (eqv? -123.0 (min -123 +inf.0 ))) | |
2795 | (pass-if (eqv? -123.3 (min +inf.0 -123.3 ))) | |
2796 | (pass-if (eqv? -123.3 (min -123.3 +inf.0 ))) | |
2797 | (pass-if (eqv? -3.5 (min +inf.0 -7/2 ))) | |
2798 | (pass-if (eqv? -3.5 (min -7/2 +inf.0 ))) | |
2799 | (pass-if (eqv? -1.0e20 (min +inf.0 -1e20 ))) | |
2800 | (pass-if (eqv? -1.0e20 (min -1e20 +inf.0 ))) | |
2801 | (pass-if (eqv? (exact->inexact (- big*2)) | |
2802 | (min +inf.0 (- big*2)))) | |
2803 | (pass-if (eqv? (exact->inexact (- big*2)) | |
2804 | (min (- big*2) +inf.0 )))) | |
2805 | ||
2806 | (with-test-prefix "signed zeroes" | |
2807 | (pass-if (eqv? 0.0 (min 0.0 0.0))) | |
2808 | (pass-if (eqv? -0.0 (min 0.0 -0.0))) | |
2809 | (pass-if (eqv? -0.0 (min -0.0 0.0))) | |
2810 | (pass-if (eqv? -0.0 (min -0.0 -0.0))) | |
2811 | (pass-if (eqv? -0.0 (min -0.0 0 ))) | |
2812 | (pass-if (eqv? 0.0 (min 0.0 0 ))) | |
2813 | (pass-if (eqv? -0.0 (min 0 -0.0))) | |
2814 | (pass-if (eqv? 0.0 (min 0 0.0))) | |
2815 | (pass-if (eqv? 0 (min 0 0 )))) | |
23d77957 | 2816 | |
2530518e | 2817 | (with-test-prefix "big / frac" |
2e274311 MW |
2818 | (pass-if (eqv? 5/2 (min big*2 5/2))) |
2819 | (pass-if (eqv? (- big*2) (min (- big*2) 5/2)))) | |
2530518e KR |
2820 | |
2821 | (with-test-prefix "frac / big" | |
2e274311 MW |
2822 | (pass-if (eqv? 5/2 (min 5/2 big*2))) |
2823 | (pass-if (eqv? (- big*2) (min 5/2 (- big*2))))) | |
2530518e | 2824 | |
23d77957 | 2825 | (with-test-prefix "big / real" |
55a8b708 | 2826 | (pass-if (real-nan? (min big*5 +nan.0))) |
23d72566 KR |
2827 | (pass-if (eqv? (exact->inexact big*5) (min big*5 +inf.0))) |
2828 | (pass-if (eqv? -inf.0 (min big*5 -inf.0))) | |
2829 | (pass-if (eqv? 1.0 (min big*5 1.0))) | |
2830 | (pass-if (eqv? (exact->inexact (- big*5)) (min (- big*5) 1.0)))) | |
23d77957 KR |
2831 | |
2832 | (with-test-prefix "real / big" | |
55a8b708 | 2833 | (pass-if (real-nan? (min +nan.0 big*5))) |
23d72566 KR |
2834 | (pass-if (eqv? (exact->inexact big*5) (min +inf.0 big*5))) |
2835 | (pass-if (eqv? -inf.0 (min -inf.0 big*5))) | |
2836 | (pass-if (eqv? 1.0 (min 1.0 big*5))) | |
2837 | (pass-if (eqv? (exact->inexact (- big*5)) (min 1.0 (- big*5))))) | |
23d77957 | 2838 | |
2530518e | 2839 | (with-test-prefix "frac / frac" |
2e274311 MW |
2840 | (pass-if (eqv? 1/2 (min 1/2 2/3))) |
2841 | (pass-if (eqv? 1/2 (min 2/3 1/2))) | |
2842 | (pass-if (eqv? -2/3 (min -1/2 -2/3))) | |
2843 | (pass-if (eqv? -2/3 (min -2/3 -1/2)))) | |
2530518e | 2844 | |
23d77957 | 2845 | (with-test-prefix "real / real" |
55a8b708 MW |
2846 | (pass-if (real-nan? (min 123.0 +nan.0))) |
2847 | (pass-if (real-nan? (min +nan.0 123.0))) | |
2848 | (pass-if (real-nan? (min +nan.0 +nan.0))) | |
2e274311 MW |
2849 | (pass-if (eqv? 123.0 (min 123.0 456.0))) |
2850 | (pass-if (eqv? 123.0 (min 456.0 123.0))))) | |
23d77957 KR |
2851 | |
2852 | ||
adda36ed KR |
2853 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating Inf as 2^1024, make |
2854 | ;; sure we've avoided that | |
2855 | (for-each (lambda (b) | |
2856 | (pass-if (list b +inf.0) | |
2e274311 | 2857 | (eqv? (exact->inexact b) (min b +inf.0))) |
adda36ed | 2858 | (pass-if (list +inf.0 b) |
2e274311 | 2859 | (eqv? (exact->inexact b) (min b +inf.0))) |
adda36ed | 2860 | (pass-if (list b -inf.0) |
2e274311 | 2861 | (eqv? -inf.0 (min b -inf.0))) |
adda36ed | 2862 | (pass-if (list -inf.0 b) |
2e274311 | 2863 | (eqv? -inf.0 (min b -inf.0)))) |
adda36ed KR |
2864 | (list (1- (ash 1 1024)) |
2865 | (ash 1 1024) | |
2866 | (1+ (ash 1 1024)) | |
2867 | (- (1- (ash 1 1024))) | |
2868 | (- (ash 1 1024)) | |
501da403 KR |
2869 | (- (1+ (ash 1 1024))))) |
2870 | ||
2871 | ;; in gmp prior to 4.2, mpz_cmp_d ended up treating NaN as 3*2^1023, make | |
2872 | ;; sure we've avoided that | |
55a8b708 MW |
2873 | (pass-if (real-nan? (min (- (ash 1 2048)) (- +nan.0)))) |
2874 | (pass-if (real-nan? (min (- +nan.0) (- (ash 1 2048)))))) | |
adda36ed | 2875 | |
f29b3454 DH |
2876 | ;;; |
2877 | ;;; + | |
2878 | ;;; | |
2879 | ||
0c57673a | 2880 | (with-test-prefix/c&e "+" |
f29b3454 | 2881 | |
d389e966 | 2882 | (pass-if "documented?" |
0c57673a LC |
2883 | (documented? +)) |
2884 | ||
c7218482 MW |
2885 | (pass-if "simple" |
2886 | (and (eqv? 7 (+ 3 4)) | |
2887 | (eqv? 3 (+ 3)) | |
2888 | (eqv? 0 (+)))) | |
2889 | ||
2890 | (pass-if "exactness propagation" | |
2891 | (and (eqv? 8 (+ 3 5)) | |
2892 | (eqv? 8.0 (+ 3 5.0)) | |
2893 | (eqv? 8.0 (+ 3.0 5)) | |
2894 | (eqv? 8.0 (+ 3.0 5.0)) | |
2895 | ||
2896 | (eqv? 5/6 (+ 1/2 1/3)) | |
2897 | (eqv? 5.5 (+ 1/2 5.0)) | |
2898 | (eqv? 3.25 (+ 3.0 1/4)))) | |
2899 | ||
2900 | (pass-if "signed zeroes" | |
2901 | (and (eqv? 0.0 (+ 0.0)) | |
2902 | (eqv? -0.0 (+ -0.0)) | |
2903 | (eqv? 0.0 (+ 0.0 0.0)) | |
2904 | (eqv? 0.0 (+ 0.0 -0.0)) | |
2905 | (eqv? 0.0 (+ -0.0 0.0)) | |
2906 | (eqv? -0.0 (+ -0.0 -0.0)))) | |
2907 | ||
2908 | (pass-if "NaNs" | |
2909 | (and (real-nan? (+ +nan.0 +nan.0)) | |
2910 | (real-nan? (+ 0 +nan.0)) | |
2911 | (real-nan? (+ +nan.0 0)) | |
2912 | (real-nan? (+ 1 +nan.0)) | |
2913 | (real-nan? (+ +nan.0 1)) | |
2914 | (real-nan? (+ -1 +nan.0)) | |
2915 | (real-nan? (+ +nan.0 -1)) | |
2916 | (real-nan? (+ -7/2 +nan.0)) | |
2917 | (real-nan? (+ +nan.0 -7/2)) | |
2918 | (real-nan? (+ 1e20 +nan.0)) | |
2919 | (real-nan? (+ +nan.0 1e20)) | |
2920 | (real-nan? (+ +inf.0 +nan.0)) | |
2921 | (real-nan? (+ +nan.0 +inf.0)) | |
2922 | (real-nan? (+ -inf.0 +nan.0)) | |
2923 | (real-nan? (+ +nan.0 -inf.0)) | |
2924 | (real-nan? (+ (* fixnum-max 2) +nan.0)) | |
2925 | (real-nan? (+ +nan.0 (* fixnum-max 2))))) | |
2926 | ||
2927 | (pass-if "infinities" | |
2928 | (and (eqv? +inf.0 (+ +inf.0 +inf.0)) | |
2929 | (eqv? -inf.0 (+ -inf.0 -inf.0)) | |
2930 | (real-nan? (+ +inf.0 -inf.0)) | |
2931 | (real-nan? (+ -inf.0 +inf.0)))) | |
2932 | ||
0c57673a LC |
2933 | ;; The maximum fixnum on a 32-bit architecture: 2^29 - 1. |
2934 | (pass-if "fixnum + fixnum = bignum (32-bit)" | |
2935 | (eqv? 536870912 (+ 536870910 2))) | |
2936 | ||
2937 | ;; The maximum fixnum on a 64-bit architecture: 2^61 - 1. | |
2938 | (pass-if "fixnum + fixnum = bignum (64-bit)" | |
2939 | (eqv? 2305843009213693952 (+ 2305843009213693950 2))) | |
2940 | ||
2941 | (pass-if "bignum + fixnum = fixnum" | |
2942 | (eqv? 0 (+ (1+ most-positive-fixnum) most-negative-fixnum)))) | |
f29b3454 | 2943 | |
f29b3454 DH |
2944 | ;;; |
2945 | ;;; - | |
2946 | ;;; | |
2947 | ||
0c57673a | 2948 | (with-test-prefix/c&e "-" |
072e6de2 | 2949 | |
b5c40589 MW |
2950 | (pass-if "double-negation of fixnum-min: =" |
2951 | (= fixnum-min (- (- fixnum-min)))) | |
2952 | (pass-if "double-negation of fixnum-min: eqv?" | |
2953 | (eqv? fixnum-min (- (- fixnum-min)))) | |
2954 | (pass-if "double-negation of fixnum-min: equal?" | |
2955 | (equal? fixnum-min (- (- fixnum-min)))) | |
2956 | ||
2957 | (pass-if "binary double-negation of fixnum-min: =" | |
2958 | (= fixnum-min (- 0 (- 0 fixnum-min)))) | |
2959 | (pass-if "binary double-negation of fixnum-min: eqv?" | |
2960 | (eqv? fixnum-min (- 0 (- 0 fixnum-min)))) | |
2961 | (pass-if "binary double-negation of fixnum-min: equal?" | |
2962 | (equal? fixnum-min (- 0 (- 0 fixnum-min)))) | |
2963 | ||
9b9ef10c MW |
2964 | (pass-if "signed zeroes" |
2965 | (and (eqv? +0.0 (- -0.0)) | |
2966 | (eqv? -0.0 (- +0.0)) | |
2967 | (eqv? 0.0 (- 0.0 0.0)) | |
2968 | (eqv? 0.0 (- 0.0 -0.0)) | |
2969 | (eqv? 0.0 (- -0.0 -0.0)) | |
2970 | (eqv? -0.0 (- -0.0 0.0)))) | |
2971 | ||
2972 | (pass-if "exactness propagation" | |
2973 | (and (eqv? 3 (- 8 5)) | |
2974 | (eqv? 3.0 (- 8 5.0)) | |
2975 | (eqv? 3.0 (- 8.0 5)) | |
2976 | (eqv? 3.0 (- 8.0 5.0)) | |
2977 | (eqv? -1/6 (- 1/3 1/2)) | |
2978 | (eqv? -4.5 (- 1/2 5.0)) | |
2979 | (eqv? 2.75 (- 3.0 1/4)))) | |
2980 | ||
2981 | (pass-if "infinities" | |
2982 | (and (eqv? +inf.0 (- +inf.0 -inf.0)) | |
2983 | (eqv? -inf.0 (- -inf.0 +inf.0)) | |
2984 | (real-nan? (- +inf.0 +inf.0)) | |
2985 | (real-nan? (- -inf.0 -inf.0)))) | |
2986 | ||
2987 | (pass-if "NaNs" | |
2988 | (and (real-nan? (- +nan.0 +nan.0)) | |
2989 | (real-nan? (- 0 +nan.0)) | |
2990 | (real-nan? (- +nan.0 0)) | |
2991 | (real-nan? (- 1 +nan.0)) | |
2992 | (real-nan? (- +nan.0 1)) | |
2993 | (real-nan? (- -1 +nan.0)) | |
2994 | (real-nan? (- +nan.0 -1)) | |
2995 | (real-nan? (- -7/2 +nan.0)) | |
2996 | (real-nan? (- +nan.0 -7/2)) | |
2997 | (real-nan? (- 1e20 +nan.0)) | |
2998 | (real-nan? (- +nan.0 1e20)) | |
2999 | (real-nan? (- +inf.0 +nan.0)) | |
3000 | (real-nan? (- +nan.0 +inf.0)) | |
3001 | (real-nan? (- -inf.0 +nan.0)) | |
3002 | (real-nan? (- +nan.0 -inf.0)) | |
3003 | (real-nan? (- (* fixnum-max 2) +nan.0)) | |
3004 | (real-nan? (- +nan.0 (* fixnum-max 2))))) | |
3005 | ||
3006 | (pass-if "(eqv? fixnum-min (- (- fixnum-min)))" | |
3007 | (eqv? fixnum-min (- (- fixnum-min)))) | |
3008 | (pass-if "(eqv? fixnum-min (- 0 (- 0 fixnum-min)))" | |
3009 | (eqv? fixnum-min (- 0 (- 0 fixnum-min)))) | |
3010 | (pass-if "(eqv? fixnum-num (apply - (list (apply - (list fixnum-min)))))" | |
3011 | (eqv? fixnum-min (apply - (list (apply - (list fixnum-min)))))) | |
3012 | ||
072e6de2 KR |
3013 | (pass-if "-inum - +bignum" |
3014 | (= #x-100000000000000000000000000000001 | |
ef016629 KR |
3015 | (- -1 #x100000000000000000000000000000000))) |
3016 | ||
3017 | (pass-if "big - inum" | |
3018 | (= #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF | |
3019 | (- #x100000000000000000000000000000000 1))) | |
3020 | ||
3021 | (pass-if "big - -inum" | |
3022 | (= #x100000000000000000000000000000001 | |
0c57673a LC |
3023 | (- #x100000000000000000000000000000000 -1))) |
3024 | ||
3025 | ;; The mininum fixnum on a 32-bit architecture: -2^29. | |
3026 | (pass-if "fixnum - fixnum = bignum (32-bit)" | |
3027 | (eqv? -536870912 (- -536870910 2))) | |
3028 | ||
3029 | ;; The minimum fixnum on a 64-bit architecture: -2^61. | |
3030 | (pass-if "fixnum - fixnum = bignum (64-bit)" | |
3031 | (eqv? -2305843009213693952 (- -2305843009213693950 2))) | |
3032 | ||
3033 | (pass-if "bignum - fixnum = fixnum" | |
3034 | (eqv? most-positive-fixnum (- (1+ most-positive-fixnum) 1)))) | |
072e6de2 | 3035 | |
f29b3454 DH |
3036 | ;;; |
3037 | ;;; * | |
3038 | ;;; | |
3039 | ||
65ea251e KR |
3040 | (with-test-prefix "*" |
3041 | ||
b5c40589 MW |
3042 | (with-test-prefix "double-negation of fixnum-min" |
3043 | (pass-if (= fixnum-min (* -1 (* -1 fixnum-min)))) | |
3044 | (pass-if (eqv? fixnum-min (* -1 (* -1 fixnum-min)))) | |
3045 | (pass-if (equal? fixnum-min (* -1 (* -1 fixnum-min)))) | |
3046 | (pass-if (= fixnum-min (* (* fixnum-min -1) -1))) | |
3047 | (pass-if (eqv? fixnum-min (* (* fixnum-min -1) -1))) | |
3048 | (pass-if (equal? fixnum-min (* (* fixnum-min -1) -1)))) | |
3049 | ||
c7218482 MW |
3050 | (with-test-prefix "signed zeroes" |
3051 | (pass-if (eqv? +0.0 (* +0.0 +0.0))) | |
3052 | (pass-if (eqv? -0.0 (* -0.0 +0.0))) | |
3053 | (pass-if (eqv? +0.0 (* -0.0 -0.0))) | |
3054 | (pass-if (eqv? -0.0 (* +0.0 -0.0))) | |
3055 | (pass-if (eqv? +0.0+0.0i (* +i +0.0))) | |
3056 | (pass-if (eqv? +0.0-0.0i (* -i +0.0))) | |
3057 | (pass-if (eqv? -0.0-0.0i (* +i -0.0))) | |
3058 | (pass-if (eqv? -0.0+0.0i (* -i -0.0)))) | |
3059 | ||
5e791807 MW |
3060 | (with-test-prefix "exactness propagation" |
3061 | (pass-if (eqv? -0.0 (* 0 -1.0 ))) | |
3062 | (pass-if (eqv? 0.0 (* 0 1.0 ))) | |
3063 | (pass-if (eqv? -0.0 (* -1.0 0 ))) | |
3064 | (pass-if (eqv? 0.0 (* 1.0 0 ))) | |
3065 | (pass-if (eqv? 0 (* 0 1/2 ))) | |
3066 | (pass-if (eqv? 0 (* 1/2 0 ))) | |
3067 | (pass-if (eqv? 0.0+0.0i (* 0 1+i ))) | |
3068 | (pass-if (eqv? 0.0+0.0i (* 1+i 0 ))) | |
3069 | (pass-if (eqv? -1.0 (* 1 -1.0 ))) | |
3070 | (pass-if (eqv? 1.0 (* 1 1.0 ))) | |
3071 | (pass-if (eqv? -1.0 (* -1.0 1 ))) | |
3072 | (pass-if (eqv? 1.0 (* 1.0 1 ))) | |
3073 | (pass-if (eqv? 1/2 (* 1 1/2 ))) | |
3074 | (pass-if (eqv? 1/2 (* 1/2 1 ))) | |
3075 | (pass-if (eqv? 1+i (* 1 1+i ))) | |
3076 | (pass-if (eqv? 1+i (* 1+i 1 )))) | |
3077 | ||
3078 | (with-test-prefix "propagation of NaNs" | |
3079 | (pass-if (real-nan? (* +nan.0 +nan.0))) | |
3080 | (pass-if (real-nan? (* +nan.0 1 ))) | |
3081 | (pass-if (real-nan? (* +nan.0 -1 ))) | |
3082 | (pass-if (real-nan? (* +nan.0 -7/2 ))) | |
3083 | (pass-if (real-nan? (* +nan.0 1e20 ))) | |
3084 | (pass-if (real-nan? (* 1 +nan.0))) | |
3085 | (pass-if (real-nan? (* -1 +nan.0))) | |
3086 | (pass-if (real-nan? (* -7/2 +nan.0))) | |
3087 | (pass-if (real-nan? (* 1e20 +nan.0))) | |
3088 | (pass-if (real-nan? (* +inf.0 +nan.0))) | |
3089 | (pass-if (real-nan? (* +nan.0 +inf.0))) | |
3090 | (pass-if (real-nan? (* -inf.0 +nan.0))) | |
3091 | (pass-if (real-nan? (* +nan.0 -inf.0))) | |
3092 | (pass-if (real-nan? (* (* fixnum-max 2) +nan.0))) | |
3093 | (pass-if (real-nan? (* +nan.0 (* fixnum-max 2)))) | |
3094 | ||
c7218482 MW |
3095 | (pass-if (real-nan? (* 0 +nan.0 ))) |
3096 | (pass-if (real-nan? (* +nan.0 0 ))) | |
3097 | (pass-if (almost-real-nan? (* 0 +nan.0+i))) | |
3098 | (pass-if (almost-real-nan? (* +nan.0+i 0 ))) | |
5e791807 MW |
3099 | |
3100 | (pass-if (imaginary-nan? (* 0 +nan.0i ))) | |
3101 | (pass-if (imaginary-nan? (* +nan.0i 0 ))) | |
3102 | (pass-if (imaginary-nan? (* 0 1+nan.0i ))) | |
3103 | (pass-if (imaginary-nan? (* 1+nan.0i 0 ))) | |
3104 | ||
3105 | (pass-if (complex-nan? (* 0 +nan.0+nan.0i ))) | |
3106 | (pass-if (complex-nan? (* +nan.0+nan.0i 0 )))) | |
3107 | ||
3108 | (with-test-prefix "infinities" | |
3109 | (pass-if (eqv? +inf.0 (* +inf.0 5 ))) | |
3110 | (pass-if (eqv? -inf.0 (* +inf.0 -5 ))) | |
3111 | (pass-if (eqv? +inf.0 (* +inf.0 73.1))) | |
3112 | (pass-if (eqv? -inf.0 (* +inf.0 -9.2))) | |
3113 | (pass-if (eqv? +inf.0 (* +inf.0 5/2))) | |
3114 | (pass-if (eqv? -inf.0 (* +inf.0 -5/2))) | |
3115 | (pass-if (eqv? -inf.0 (* -5 +inf.0))) | |
3116 | (pass-if (eqv? +inf.0 (* 73.1 +inf.0))) | |
3117 | (pass-if (eqv? -inf.0 (* -9.2 +inf.0))) | |
3118 | (pass-if (eqv? +inf.0 (* 5/2 +inf.0))) | |
3119 | (pass-if (eqv? -inf.0 (* -5/2 +inf.0))) | |
3120 | ||
3121 | (pass-if (eqv? -inf.0 (* -inf.0 5 ))) | |
3122 | (pass-if (eqv? +inf.0 (* -inf.0 -5 ))) | |
3123 | (pass-if (eqv? -inf.0 (* -inf.0 73.1))) | |
3124 | (pass-if (eqv? +inf.0 (* -inf.0 -9.2))) | |
3125 | (pass-if (eqv? -inf.0 (* -inf.0 5/2))) | |
3126 | (pass-if (eqv? +inf.0 (* -inf.0 -5/2))) | |
3127 | (pass-if (eqv? +inf.0 (* -5 -inf.0))) | |
3128 | (pass-if (eqv? -inf.0 (* 73.1 -inf.0))) | |
3129 | (pass-if (eqv? +inf.0 (* -9.2 -inf.0))) | |
3130 | (pass-if (eqv? -inf.0 (* 5/2 -inf.0))) | |
3131 | (pass-if (eqv? +inf.0 (* -5/2 -inf.0))) | |
3132 | ||
3133 | (pass-if (real-nan? (* 0.0 +inf.0))) | |
3134 | (pass-if (real-nan? (* -0.0 +inf.0))) | |
3135 | (pass-if (real-nan? (* +inf.0 0.0))) | |
3136 | (pass-if (real-nan? (* +inf.0 -0.0))) | |
3137 | ||
3138 | (pass-if (real-nan? (* 0.0 -inf.0))) | |
3139 | (pass-if (real-nan? (* -0.0 -inf.0))) | |
3140 | (pass-if (real-nan? (* -inf.0 0.0))) | |
3141 | (pass-if (real-nan? (* -inf.0 -0.0))) | |
3142 | ||
3143 | (pass-if (real-nan? (* 0 +inf.0 ))) | |
3144 | (pass-if (real-nan? (* +inf.0 0 ))) | |
5e791807 MW |
3145 | (pass-if (real-nan? (* 0 -inf.0 ))) |
3146 | (pass-if (real-nan? (* -inf.0 0 ))) | |
c7218482 MW |
3147 | |
3148 | (pass-if (almost-real-nan? (* 0 +inf.0+i))) | |
3149 | (pass-if (almost-real-nan? (* +inf.0+i 0 ))) | |
3150 | (pass-if (almost-real-nan? (* 0 -inf.0+i))) | |
3151 | (pass-if (almost-real-nan? (* -inf.0+i 0 ))) | |
5e791807 MW |
3152 | |
3153 | (pass-if (imaginary-nan? (* 0 +inf.0i ))) | |
3154 | (pass-if (imaginary-nan? (* +inf.0i 0 ))) | |
3155 | (pass-if (imaginary-nan? (* 0 1+inf.0i ))) | |
3156 | (pass-if (imaginary-nan? (* 1+inf.0i 0 ))) | |
3157 | ||
3158 | (pass-if (imaginary-nan? (* 0 -inf.0i ))) | |
3159 | (pass-if (imaginary-nan? (* -inf.0i 0 ))) | |
3160 | (pass-if (imaginary-nan? (* 0 1-inf.0i ))) | |
3161 | (pass-if (imaginary-nan? (* 1-inf.0i 0 ))) | |
3162 | ||
3163 | (pass-if (complex-nan? (* 0 +inf.0+inf.0i ))) | |
3164 | (pass-if (complex-nan? (* +inf.0+inf.0i 0 ))) | |
3165 | ||
3166 | (pass-if (complex-nan? (* 0 +inf.0-inf.0i ))) | |
3167 | (pass-if (complex-nan? (* -inf.0+inf.0i 0 )))) | |
3168 | ||
23d72566 KR |
3169 | (with-test-prefix "inum * bignum" |
3170 | ||
3171 | (pass-if "0 * 2^256 = 0" | |
3172 | (eqv? 0 (* 0 (ash 1 256))))) | |
3173 | ||
3174 | (with-test-prefix "inum * flonum" | |
3175 | ||
5e791807 MW |
3176 | (pass-if "0 * 1.0 = 0.0" |
3177 | (eqv? 0.0 (* 0 1.0)))) | |
23d72566 KR |
3178 | |
3179 | (with-test-prefix "inum * complex" | |
3180 | ||
5e791807 MW |
3181 | (pass-if "0 * 1+1i = 0.0+0.0i" |
3182 | (eqv? 0.0+0.0i (* 0 1+1i)))) | |
23d72566 KR |
3183 | |
3184 | (with-test-prefix "inum * frac" | |
3185 | ||
3186 | (pass-if "0 * 2/3 = 0" | |
3187 | (eqv? 0 (* 0 2/3)))) | |
3188 | ||
3189 | (with-test-prefix "bignum * inum" | |
3190 | ||
3191 | (pass-if "2^256 * 0 = 0" | |
3192 | (eqv? 0 (* (ash 1 256) 0)))) | |
3193 | ||
3194 | (with-test-prefix "flonum * inum" | |
5e791807 MW |
3195 | (pass-if "1.0 * 0 = 0.0" |
3196 | (eqv? 0.0 (* 1.0 0)))) | |
23d72566 KR |
3197 | |
3198 | (with-test-prefix "complex * inum" | |
5e791807 MW |
3199 | (pass-if "1+1i * 0 = 0.0+0.0i" |
3200 | (eqv? 0.0+0.0i (* 1+1i 0)))) | |
23d72566 | 3201 | |
65ea251e KR |
3202 | (pass-if "complex * bignum" |
3203 | (let ((big (ash 1 90))) | |
3204 | (= (make-rectangular big big) | |
23d72566 KR |
3205 | (* 1+1i big)))) |
3206 | ||
3207 | (with-test-prefix "frac * inum" | |
3208 | ||
3209 | (pass-if "2/3 * 0 = 0" | |
3210 | (eqv? 0 (* 2/3 0))))) | |
65ea251e | 3211 | |
f29b3454 DH |
3212 | ;;; |
3213 | ;;; / | |
3214 | ;;; | |
3215 | ||
1b3a7932 DH |
3216 | (with-test-prefix "/" |
3217 | ||
b5c40589 MW |
3218 | (with-test-prefix "double-negation of fixnum-min" |
3219 | (pass-if (= fixnum-min (/ (/ fixnum-min -1) -1))) | |
3220 | (pass-if (eqv? fixnum-min (/ (/ fixnum-min -1) -1))) | |
3221 | (pass-if (equal? fixnum-min (/ (/ fixnum-min -1) -1)))) | |
3222 | ||
d389e966 | 3223 | (pass-if "documented?" |
1b3a7932 DH |
3224 | (documented? /)) |
3225 | ||
3226 | (with-test-prefix "division by zero" | |
3227 | ||
3228 | (pass-if-exception "(/ 0)" | |
2f359170 | 3229 | exception:numerical-overflow |
1b3a7932 DH |
3230 | (/ 0)) |
3231 | ||
cdf52e3d MV |
3232 | (pass-if "(/ 0.0)" |
3233 | (= +inf.0 (/ 0.0))) | |
80074d77 | 3234 | |
1b3a7932 | 3235 | (pass-if-exception "(/ 1 0)" |
2f359170 | 3236 | exception:numerical-overflow |
80074d77 DH |
3237 | (/ 1 0)) |
3238 | ||
cdf52e3d MV |
3239 | (pass-if "(/ 1 0.0)" |
3240 | (= +inf.0 (/ 1 0.0))) | |
80074d77 DH |
3241 | |
3242 | (pass-if-exception "(/ bignum 0)" | |
2f359170 | 3243 | exception:numerical-overflow |
80074d77 DH |
3244 | (/ (+ fixnum-max 1) 0)) |
3245 | ||
cdf52e3d MV |
3246 | (pass-if "(/ bignum 0.0)" |
3247 | (= +inf.0 (/ (+ fixnum-max 1) 0.0))) | |
80074d77 DH |
3248 | |
3249 | (pass-if-exception "(/ 1.0 0)" | |
2f359170 | 3250 | exception:numerical-overflow |
80074d77 DH |
3251 | (/ 1.0 0)) |
3252 | ||
cdf52e3d MV |
3253 | (pass-if "(/ 1.0 0.0)" |
3254 | (= +inf.0 (/ 1.0 0.0))) | |
80074d77 DH |
3255 | |
3256 | (pass-if-exception "(/ +i 0)" | |
2f359170 | 3257 | exception:numerical-overflow |
80074d77 DH |
3258 | (/ +i 0)) |
3259 | ||
cdf52e3d MV |
3260 | (pass-if "(/ +i 0.0)" |
3261 | (= +inf.0 (imag-part (/ +i 0.0))))) | |
469b963c | 3262 | |
2f359170 KR |
3263 | (with-test-prefix "1/complex" |
3264 | ||
3265 | (pass-if "0+1i" | |
3266 | (eqv? 0-1i (/ 0+1i))) | |
3267 | ||
3268 | ;; in guile 1.6 through 1.6.7 this incorrectly resulted in nans | |
3269 | (pass-if "0-1i" | |
3270 | (eqv? 0+1i (/ 0-1i))) | |
3271 | ||
3272 | (pass-if "1+1i" | |
3273 | (eqv? 0.5-0.5i (/ 1+1i))) | |
3274 | ||
3275 | (pass-if "1-1i" | |
3276 | (eqv? 0.5+0.5i (/ 1-1i))) | |
3277 | ||
3278 | (pass-if "-1+1i" | |
3279 | (eqv? -0.5-0.5i (/ -1+1i))) | |
3280 | ||
3281 | (pass-if "-1-1i" | |
3282 | (eqv? -0.5+0.5i (/ -1-1i))) | |
469b963c MV |
3283 | |
3284 | (pass-if "(/ 3+4i)" | |
3285 | (= (/ 3+4i) 0.12-0.16i)) | |
3286 | ||
3287 | (pass-if "(/ 4+3i)" | |
3288 | (= (/ 4+3i) 0.16-0.12i)) | |
3289 | ||
2f359170 KR |
3290 | (pass-if "(/ 1e200+1e200i)" |
3291 | (= (/ 1e200+1e200i) 5.0e-201-5.0e-201i))) | |
469b963c | 3292 | |
2f359170 | 3293 | (with-test-prefix "inum/complex" |
469b963c MV |
3294 | |
3295 | (pass-if "(/ 25 3+4i)" | |
3296 | (= (/ 25 3+4i) 3.0-4.0i)) | |
3297 | ||
3298 | (pass-if "(/ 25 4+3i)" | |
2f359170 | 3299 | (= (/ 25 4+3i) 4.0-3.0i))) |
469b963c | 3300 | |
2f359170 KR |
3301 | (with-test-prefix "complex/complex" |
3302 | ||
3303 | (pass-if "(/ 25+125i 3+4i)" | |
3304 | (= (/ 25+125i 3+4i) 23.0+11.0i)) | |
3305 | ||
3306 | (pass-if "(/ 25+125i 4+3i)" | |
3307 | (= (/ 25+125i 4+3i) 19.0+17.0i)))) | |
1b3a7932 | 3308 | |
f29b3454 DH |
3309 | ;;; |
3310 | ;;; truncate | |
3311 | ;;; | |
3312 | ||
14a6784c KR |
3313 | (with-test-prefix "truncate" |
3314 | (pass-if (= 1 (truncate 1.75))) | |
3315 | (pass-if (= 1 (truncate 1.5))) | |
3316 | (pass-if (= 1 (truncate 1.25))) | |
3317 | (pass-if (= 0 (truncate 0.75))) | |
3318 | (pass-if (= 0 (truncate 0.5))) | |
3319 | (pass-if (= 0 (truncate 0.0))) | |
3320 | (pass-if (= 0 (truncate -0.5))) | |
3321 | (pass-if (= -1 (truncate -1.25))) | |
3322 | (pass-if (= -1 (truncate -1.5)))) | |
3323 | ||
f29b3454 DH |
3324 | ;;; |
3325 | ;;; round | |
3326 | ;;; | |
3327 | ||
14a6784c KR |
3328 | (with-test-prefix "round" |
3329 | (pass-if (= 2 (round 1.75))) | |
3330 | (pass-if (= 2 (round 1.5))) | |
3331 | (pass-if (= 1 (round 1.25))) | |
3332 | (pass-if (= 1 (round 0.75))) | |
3333 | (pass-if (= 0 (round 0.5))) | |
3334 | (pass-if (= 0 (round 0.0))) | |
3335 | (pass-if (= 0 (round -0.5))) | |
3336 | (pass-if (= -1 (round -1.25))) | |
abff733b KR |
3337 | (pass-if (= -2 (round -1.5))) |
3338 | ||
3339 | (with-test-prefix "inum" | |
3340 | (pass-if "0" | |
3341 | (and (= 0 (round 0)) | |
3342 | (exact? (round 0)))) | |
3343 | ||
3344 | (pass-if "1" | |
3345 | (and (= 1 (round 1)) | |
3346 | (exact? (round 1)))) | |
3347 | ||
3348 | (pass-if "-1" | |
3349 | (and (= -1 (round -1)) | |
3350 | (exact? (round -1))))) | |
3351 | ||
3352 | (with-test-prefix "bignum" | |
3353 | (let ((x (1+ most-positive-fixnum))) | |
3354 | (pass-if "(1+ most-positive-fixnum)" | |
3355 | (and (= x (round x)) | |
3356 | (exact? (round x))))) | |
3357 | ||
3358 | (let ((x (1- most-negative-fixnum))) | |
3359 | (pass-if "(1- most-negative-fixnum)" | |
3360 | (and (= x (round x)) | |
3361 | (exact? (round x)))))) | |
3362 | ||
6203b5f5 KR |
3363 | (with-test-prefix "frac" |
3364 | (define (=exact x y) | |
3365 | (and (= x y) | |
3366 | (exact? y))) | |
3367 | ||
3368 | (pass-if (=exact -2 (round -7/3))) | |
3369 | (pass-if (=exact -2 (round -5/3))) | |
3370 | (pass-if (=exact -1 (round -4/3))) | |
3371 | (pass-if (=exact -1 (round -2/3))) | |
3372 | (pass-if (=exact 0 (round -1/3))) | |
3373 | (pass-if (=exact 0 (round 1/3))) | |
3374 | (pass-if (=exact 1 (round 2/3))) | |
3375 | (pass-if (=exact 1 (round 4/3))) | |
3376 | (pass-if (=exact 2 (round 5/3))) | |
3377 | (pass-if (=exact 2 (round 7/3))) | |
3378 | ||
3379 | (pass-if (=exact -3 (round -17/6))) | |
3380 | (pass-if (=exact -3 (round -16/6))) | |
3381 | (pass-if (=exact -2 (round -15/6))) | |
3382 | (pass-if (=exact -2 (round -14/6))) | |
3383 | (pass-if (=exact -2 (round -13/6))) | |
3384 | (pass-if (=exact -2 (round -11/6))) | |
3385 | (pass-if (=exact -2 (round -10/6))) | |
3386 | (pass-if (=exact -2 (round -9/6))) | |
3387 | (pass-if (=exact -1 (round -8/6))) | |
3388 | (pass-if (=exact -1 (round -7/6))) | |
3389 | (pass-if (=exact -1 (round -5/6))) | |
3390 | (pass-if (=exact -1 (round -4/6))) | |
3391 | (pass-if (=exact 0 (round -3/6))) | |
3392 | (pass-if (=exact 0 (round -2/6))) | |
3393 | (pass-if (=exact 0 (round -1/6))) | |
3394 | (pass-if (=exact 0 (round 1/6))) | |
3395 | (pass-if (=exact 0 (round 2/6))) | |
3396 | (pass-if (=exact 0 (round 3/6))) | |
3397 | (pass-if (=exact 1 (round 4/6))) | |
3398 | (pass-if (=exact 1 (round 5/6))) | |
3399 | (pass-if (=exact 1 (round 7/6))) | |
3400 | (pass-if (=exact 1 (round 8/6))) | |
3401 | (pass-if (=exact 2 (round 9/6))) | |
3402 | (pass-if (=exact 2 (round 10/6))) | |
3403 | (pass-if (=exact 2 (round 11/6))) | |
3404 | (pass-if (=exact 2 (round 13/6))) | |
3405 | (pass-if (=exact 2 (round 14/6))) | |
3406 | (pass-if (=exact 2 (round 15/6))) | |
3407 | (pass-if (=exact 3 (round 16/6))) | |
3408 | (pass-if (=exact 3 (round 17/6)))) | |
3409 | ||
abff733b KR |
3410 | (with-test-prefix "real" |
3411 | (pass-if "0.0" | |
3412 | (and (= 0.0 (round 0.0)) | |
3413 | (inexact? (round 0.0)))) | |
3414 | ||
3415 | (pass-if "1.0" | |
3416 | (and (= 1.0 (round 1.0)) | |
3417 | (inexact? (round 1.0)))) | |
3418 | ||
3419 | (pass-if "-1.0" | |
3420 | (and (= -1.0 (round -1.0)) | |
3421 | (inexact? (round -1.0)))) | |
3422 | ||
3423 | (pass-if "-3.1" | |
3424 | (and (= -3.0 (round -3.1)) | |
3425 | (inexact? (round -3.1)))) | |
3426 | ||
3427 | (pass-if "3.1" | |
3428 | (and (= 3.0 (round 3.1)) | |
3429 | (inexact? (round 3.1)))) | |
3430 | ||
3431 | (pass-if "3.9" | |
3432 | (and (= 4.0 (round 3.9)) | |
3433 | (inexact? (round 3.9)))) | |
3434 | ||
3435 | (pass-if "-3.9" | |
3436 | (and (= -4.0 (round -3.9)) | |
3437 | (inexact? (round -3.9)))) | |
3438 | ||
3439 | (pass-if "1.5" | |
3440 | (and (= 2.0 (round 1.5)) | |
3441 | (inexact? (round 1.5)))) | |
3442 | ||
3443 | (pass-if "2.5" | |
3444 | (and (= 2.0 (round 2.5)) | |
3445 | (inexact? (round 2.5)))) | |
3446 | ||
3447 | (pass-if "3.5" | |
3448 | (and (= 4.0 (round 3.5)) | |
3449 | (inexact? (round 3.5)))) | |
3450 | ||
3451 | (pass-if "-1.5" | |
3452 | (and (= -2.0 (round -1.5)) | |
3453 | (inexact? (round -1.5)))) | |
3454 | ||
3455 | (pass-if "-2.5" | |
3456 | (and (= -2.0 (round -2.5)) | |
3457 | (inexact? (round -2.5)))) | |
3458 | ||
3459 | (pass-if "-3.5" | |
3460 | (and (= -4.0 (round -3.5)) | |
3461 | (inexact? (round -3.5)))) | |
3462 | ||
3463 | ;; prior to guile 1.6.5, on an IEEE system an inexact 2^53-1 (ie. a | |
3464 | ;; float with mantissa all ones) came out as 2^53 from `round' (except | |
3465 | ;; on i386 and m68k systems using the coprocessor and optimizing, where | |
3466 | ;; extra precision hid the problem) | |
3467 | (pass-if "2^53-1" | |
3468 | (let ((x (exact->inexact (1- (ash 1 53))))) | |
3469 | (and (= x (round x)) | |
3470 | (inexact? (round x))))) | |
3471 | (pass-if "-(2^53-1)" | |
3472 | (let ((x (exact->inexact (- (1- (ash 1 53)))))) | |
3473 | (and (= x (round x)) | |
3474 | (inexact? (round x))))))) | |
14a6784c | 3475 | |
f29b3454 DH |
3476 | ;;; |
3477 | ;;; exact->inexact | |
3478 | ;;; | |
3479 | ||
a1fb3b1c KR |
3480 | (with-test-prefix "exact->inexact" |
3481 | ||
3482 | ;; Test "(exact->inexact n)", expect "want". | |
3483 | ;; "i" is a index, for diagnostic purposes. | |
3484 | (define (try-i i n want) | |
3485 | (with-test-prefix (list i n want) | |
3486 | (with-test-prefix "pos" | |
3487 | (let ((got (exact->inexact n))) | |
3488 | (pass-if "inexact?" (inexact? got)) | |
3489 | (pass-if (list "=" got) (= want got)))) | |
3490 | (set! n (- n)) | |
3491 | (set! want (- want)) | |
3492 | (with-test-prefix "neg" | |
3493 | (let ((got (exact->inexact n))) | |
3494 | (pass-if "inexact?" (inexact? got)) | |
3495 | (pass-if (list "=" got) (= want got)))))) | |
3496 | ||
3497 | (with-test-prefix "2^i, no round" | |
3498 | (do ((i 0 (1+ i)) | |
3499 | (n 1 (* 2 n)) | |
3500 | (want 1.0 (* 2.0 want))) | |
3501 | ((> i 100)) | |
3502 | (try-i i n want))) | |
3503 | ||
3504 | (with-test-prefix "2^i+1, no round" | |
3505 | (do ((i 1 (1+ i)) | |
3506 | (n 3 (1- (* 2 n))) | |
3507 | (want 3.0 (- (* 2.0 want) 1.0))) | |
3508 | ((>= i dbl-mant-dig)) | |
3509 | (try-i i n want))) | |
3510 | ||
3511 | (with-test-prefix "(2^i+1)*2^100, no round" | |
3512 | (do ((i 1 (1+ i)) | |
3513 | (n 3 (1- (* 2 n))) | |
3514 | (want 3.0 (- (* 2.0 want) 1.0))) | |
3515 | ((>= i dbl-mant-dig)) | |
3516 | (try-i i (ash n 100) (ash-flo want 100)))) | |
3517 | ||
3518 | ;; bit pattern: 1111....11100.00 | |
3519 | ;; <-mantdig-><-i-> | |
3520 | ;; | |
3521 | (with-test-prefix "mantdig ones then zeros, no rounding" | |
3522 | (do ((i 0 (1+ i)) | |
3523 | (n (- (ash 1 dbl-mant-dig) 1) (* 2 n)) | |
3524 | (want (- (ash-flo 1.0 dbl-mant-dig) 1.0) (* 2.0 want))) | |
3525 | ((> i 100)) | |
3526 | (try-i i n want))) | |
3527 | ||
3528 | ;; bit pattern: 1111....111011..1 | |
3529 | ;; <-mantdig-> <-i-> | |
3530 | ;; This sort of value was incorrectly rounded upwards in Guile 1.6.4 when | |
3531 | ;; i >= 11 (that's when the total is 65 or more bits). | |
3532 | ;; | |
3533 | (with-test-prefix "mantdig ones then 011..11, round down" | |
3534 | (do ((i 0 (1+ i)) | |
3535 | (n (- (ash 1 (+ 1 dbl-mant-dig)) 2) (+ 1 (* 2 n))) | |
3536 | (want (- (ash-flo 1.0 (+ 1 dbl-mant-dig)) 2.0) (* 2.0 want))) | |
3537 | ((> i 100)) | |
3538 | (try-i i n want))) | |
3539 | ||
3540 | ;; bit pattern: 1111....111100..001 | |
3541 | ;; <-mantdig-> <--i-> | |
3542 | ;; | |
3543 | (with-test-prefix "mantdig ones then 100..001, round up" | |
3544 | (do ((i 0 (1+ i)) | |
3545 | (n (- (ash 1 (+ 2 dbl-mant-dig)) 1) (1- (* 2 n))) | |
3546 | (want (ash-flo 1.0 (+ 2 dbl-mant-dig)) (* 2.0 want))) | |
3547 | ((> i 100)) | |
3548 | (try-i i n want))) | |
3549 | ||
3550 | ;; bit pattern: 1000....000100..001 | |
3551 | ;; <-mantdig-> <--i-> | |
3552 | ;; | |
3553 | (with-test-prefix "2^mantdig then 100..001, round up" | |
3554 | (do ((i 0 (1+ i)) | |
3555 | (n (- (ash 1 (+ 2 dbl-mant-dig)) 1) (1- (* 2 n))) | |
3556 | (want (+ (ash-flo 1.0 (+ 2 dbl-mant-dig)) 4.0) (* 2.0 want))) | |
3557 | ((> i 100)) | |
23f2b9a3 KR |
3558 | (try-i i n want))) |
3559 | ||
3560 | (pass-if "frac big/big" | |
3561 | (let ((big (ash 1 256))) | |
3562 | (= 1.0 (exact->inexact (/ (1+ big) big))))) | |
3563 | ||
3564 | ;; In guile 1.8.0 this failed, giving back "nan" because it tried to | |
3565 | ;; convert the num and den to doubles, resulting in infs. | |
3566 | (pass-if "frac big/big, exceeding double" | |
3567 | (let ((big (ash 1 4096))) | |
3568 | (= 1.0 (exact->inexact (/ (1+ big) big)))))) | |
a1fb3b1c | 3569 | |
f29b3454 DH |
3570 | ;;; |
3571 | ;;; floor | |
3572 | ;;; | |
3573 | ||
3574 | ;;; | |
3575 | ;;; ceiling | |
3576 | ;;; | |
3577 | ||
46f2c0f1 RB |
3578 | ;;; |
3579 | ;;; expt | |
3580 | ;;; | |
3581 | ||
3582 | (with-test-prefix "expt" | |
2519490c | 3583 | (pass-if (documented? expt)) |
bfe1f03a MW |
3584 | |
3585 | ;; | |
3586 | ;; expt no longer requires its first argument to be a scheme number, | |
3587 | ;; for the sake of extensibility, and expt calls integer-expt for | |
3588 | ;; integer powers. To raise to a positive power, all that is required | |
3589 | ;; is that it can be multiplied using `*'. For negative powers we | |
3590 | ;; must also be able to find the reciprocal. If we try to raise #t to | |
3591 | ;; any power other than 0 or 1 it may throw an exception, depending on | |
3592 | ;; whether * has been defined for #t. However, when raising to the 0 | |
3593 | ;; or 1 power, the first argument is not manipulated at all. | |
3594 | ;; | |
3595 | ;; (pass-if-exception "non-numeric base" exception:wrong-type-arg | |
3596 | ;; (expt #t 0)) | |
3597 | ;; | |
3598 | ||
01c7284a MW |
3599 | (pass-if (eqv? 1 (expt 0 0))) |
3600 | (pass-if (eqv? 1 (expt 0.0 0))) | |
3601 | (pass-if (eqv? 1.0 (expt 0 0.0))) | |
3602 | (pass-if (eqv? 1.0 (expt 0.0 0.0))) | |
55a8b708 MW |
3603 | (pass-if (real-nan? (expt 0 -1))) |
3604 | (pass-if (real-nan? (expt 0 -1.0))) | |
3605 | (pass-if (real-nan? (expt 0.0 -1))) | |
3606 | (pass-if (real-nan? (expt 0.0 -1.0))) | |
01c7284a MW |
3607 | (pass-if (eqv? 0 (expt 0 3))) |
3608 | (pass-if (= 0 (expt 0 4.0))) | |
3609 | (pass-if (eqv? 0.0 (expt 0.0 5))) | |
3610 | (pass-if (eqv? 0.0 (expt 0.0 6.0))) | |
3611 | (pass-if (eqv? -2742638075.5 (expt -2742638075.5 1))) | |
3612 | (pass-if (eqv? (* -2742638075.5 -2742638075.5) | |
3613 | (expt -2742638075.5 2))) | |
3614 | (pass-if (eqv? 4.0 (expt -2.0 2.0))) | |
3615 | (pass-if (eqv? -1/8 (expt -2 -3))) | |
3616 | (pass-if (eqv? -0.125 (expt -2.0 -3))) | |
3617 | (pass-if (eqv? -0.125 (expt -2 -3.0))) | |
3618 | (pass-if (eqv? -0.125 (expt -2.0 -3.0))) | |
3619 | (pass-if (eqv? 0.25 (expt 2.0 -2.0))) | |
c7218482 | 3620 | (pass-if (test-eqv? (* -1.0+0.0i 12398 12398) (expt +12398i 2.0))) |
01c7284a MW |
3621 | (pass-if (eqv-loosely? +i (expt -1 0.5))) |
3622 | (pass-if (eqv-loosely? +i (expt -1 1/2))) | |
8e43ed5d AW |
3623 | (pass-if (eqv-loosely? 1.0+1.7320508075688i (expt -8 1/3))) |
3624 | (pass-if (eqv? +inf.0 (expt 2 +inf.0))) | |
3625 | (pass-if (eqv? +inf.0 (expt 2.0 +inf.0))) | |
3626 | (pass-if (eqv? 0.0 (expt 2 -inf.0))) | |
3627 | (pass-if (eqv? 0.0 (expt 2.0 -inf.0)))) | |
01c7284a | 3628 | |
46f2c0f1 | 3629 | |
8deddc94 MW |
3630 | ;;; |
3631 | ;;; sin | |
3632 | ;;; | |
3633 | ||
3634 | (with-test-prefix "sin" | |
3635 | (pass-if (eqv? 0 (sin 0))) | |
3636 | (pass-if (eqv? 0.0 (sin 0.0))) | |
3637 | (pass-if (eqv-loosely? 1.0 (sin 1.57))) | |
3638 | (pass-if (eqv-loosely? +1.175i (sin +i))) | |
3639 | (pass-if (real-nan? (sin +nan.0))) | |
3640 | (pass-if (real-nan? (sin +inf.0))) | |
3641 | (pass-if (real-nan? (sin -inf.0)))) | |
3642 | ||
3643 | ;;; | |
3644 | ;;; cos | |
3645 | ;;; | |
3646 | ||
3647 | (with-test-prefix "cos" | |
3648 | (pass-if (eqv? 1 (cos 0))) | |
3649 | (pass-if (eqv? 1.0 (cos 0.0))) | |
3650 | (pass-if (eqv-loosely? 0.0 (cos 1.57))) | |
3651 | (pass-if (eqv-loosely? 1.543 (cos +i))) | |
3652 | (pass-if (real-nan? (cos +nan.0))) | |
3653 | (pass-if (real-nan? (cos +inf.0))) | |
3654 | (pass-if (real-nan? (cos -inf.0)))) | |
3655 | ||
3656 | ;;; | |
3657 | ;;; tan | |
3658 | ;;; | |
3659 | ||
3660 | (with-test-prefix "tan" | |
3661 | (pass-if (eqv? 0 (tan 0))) | |
3662 | (pass-if (eqv? 0.0 (tan 0.0))) | |
3663 | (pass-if (eqv-loosely? 1.0 (tan 0.785))) | |
3664 | (pass-if (eqv-loosely? +0.76i (tan +i))) | |
3665 | (pass-if (real-nan? (tan +nan.0))) | |
3666 | (pass-if (real-nan? (tan +inf.0))) | |
3667 | (pass-if (real-nan? (tan -inf.0)))) | |
3668 | ||
3669 | ;;; | |
3670 | ;;; asin | |
3671 | ;;; | |
3672 | ||
3673 | (with-test-prefix "asin" | |
3674 | (pass-if (complex-nan? (asin +nan.0))) | |
3675 | (pass-if (eqv? 0 (asin 0))) | |
3676 | (pass-if (eqv? 0.0 (asin 0.0)))) | |
3677 | ||
3678 | ;;; | |
3679 | ;;; acos | |
3680 | ;;; | |
3681 | ||
3682 | (with-test-prefix "acos" | |
3683 | (pass-if (complex-nan? (acos +nan.0))) | |
3684 | (pass-if (eqv? 0 (acos 1))) | |
3685 | (pass-if (eqv? 0.0 (acos 1.0)))) | |
3686 | ||
3687 | ;;; | |
3688 | ;;; atan | |
3689 | ;;; | |
3690 | ;;; FIXME: add tests for two-argument atan | |
3691 | ;;; | |
3692 | (with-test-prefix "atan" | |
3693 | (pass-if (real-nan? (atan +nan.0))) | |
3694 | (pass-if (eqv? 0 (atan 0))) | |
3695 | (pass-if (eqv? 0.0 (atan 0.0))) | |
3696 | (pass-if (eqv-loosely? 1.57 (atan +inf.0))) | |
3697 | (pass-if (eqv-loosely? -1.57 (atan -inf.0)))) | |
3698 | ||
3699 | ;;; | |
3700 | ;;; sinh | |
3701 | ;;; | |
3702 | ||
3703 | (with-test-prefix "sinh" | |
3704 | (pass-if (= 0 (sinh 0))) | |
3705 | (pass-if (= 0.0 (sinh 0.0)))) | |
3706 | ||
3707 | ;;; | |
3708 | ;;; cosh | |
3709 | ;;; | |
3710 | ||
3711 | (with-test-prefix "cosh" | |
3712 | (pass-if (= 1 (cosh 0))) | |
3713 | (pass-if (= 1.0 (cosh 0.0)))) | |
3714 | ||
3715 | ;;; | |
3716 | ;;; tanh | |
3717 | ;;; | |
3718 | ||
3719 | (with-test-prefix "tanh" | |
3720 | (pass-if (= 0 (tanh 0))) | |
3721 | (pass-if (= 0.0 (tanh 0.0)))) | |
3722 | ||
14a6784c KR |
3723 | ;;; |
3724 | ;;; asinh | |
3725 | ;;; | |
3726 | ||
3727 | (with-test-prefix "asinh" | |
8deddc94 MW |
3728 | (pass-if (= 0 (asinh 0))) |
3729 | (pass-if (= 0.0 (asinh 0.0)))) | |
14a6784c KR |
3730 | |
3731 | ;;; | |
3732 | ;;; acosh | |
3733 | ;;; | |
3734 | ||
3735 | (with-test-prefix "acosh" | |
8deddc94 MW |
3736 | (pass-if (= 0 (acosh 1))) |
3737 | (pass-if (= 0.0 (acosh 1.0)))) | |
14a6784c KR |
3738 | |
3739 | ;;; | |
3740 | ;;; atanh | |
3741 | ;;; | |
3742 | ||
3743 | (with-test-prefix "atanh" | |
8deddc94 MW |
3744 | (pass-if (= 0 (atanh 0))) |
3745 | (pass-if (= 0.0 (atanh 0.0)))) | |
14a6784c | 3746 | |
f29b3454 DH |
3747 | ;;; |
3748 | ;;; make-rectangular | |
3749 | ;;; | |
c7218482 MW |
3750 | |
3751 | (with-test-prefix "make-rectangular" | |
3752 | (pass-if (real? (make-rectangular 5.0 0 ))) | |
3753 | (pass-if (not (real? (make-rectangular 5.0 0.0)))) | |
3754 | (pass-if (not (real? (make-rectangular 5.0 -0.0))))) | |
f29b3454 DH |
3755 | |
3756 | ;;; | |
3757 | ;;; make-polar | |
3758 | ;;; | |
3759 | ||
d40681ec KR |
3760 | (with-test-prefix "make-polar" |
3761 | (define pi 3.14159265358979323846) | |
3762 | (define (almost= x y) | |
3763 | (> 0.01 (magnitude (- x y)))) | |
3764 | ||
c7218482 MW |
3765 | (pass-if (real? (make-polar 0 1.0))) |
3766 | (pass-if (real? (make-polar 5.0 0 ))) | |
3767 | (pass-if (not (real? (make-polar 5.0 0.0)))) | |
3768 | (pass-if (not (real? (make-polar 5.0 -0.0)))) | |
3769 | ||
3770 | (pass-if (eqv? 0 (make-polar 0 0))) | |
3771 | (pass-if (eqv? 0 (make-polar 0 123.456))) | |
3772 | (pass-if (eqv? 1 (make-polar 1 0))) | |
3773 | (pass-if (eqv? -1 (make-polar -1 0))) | |
d40681ec KR |
3774 | |
3775 | (pass-if (almost= 0+i (make-polar 1 (* 0.5 pi)))) | |
3776 | (pass-if (almost= -1 (make-polar 1 (* 1.0 pi)))) | |
3777 | (pass-if (almost= 0-i (make-polar 1 (* 1.5 pi)))) | |
3778 | (pass-if (almost= 1 (make-polar 1 (* 2.0 pi))))) | |
3779 | ||
f29b3454 DH |
3780 | ;;; |
3781 | ;;; real-part | |
3782 | ;;; | |
3783 | ||
2519490c MW |
3784 | (with-test-prefix "real-part" |
3785 | (pass-if (documented? real-part)) | |
3786 | (pass-if (eqv? 5.0 (real-part 5.0))) | |
3787 | (pass-if (eqv? 0.0 (real-part +5.0i))) | |
3788 | (pass-if (eqv? 5 (real-part 5))) | |
3789 | (pass-if (eqv? 1/5 (real-part 1/5))) | |
3790 | (pass-if (eqv? (1+ fixnum-max) (real-part (1+ fixnum-max))))) | |
3791 | ||
f29b3454 DH |
3792 | ;;; |
3793 | ;;; imag-part | |
3794 | ;;; | |
3795 | ||
2519490c MW |
3796 | (with-test-prefix "imag-part" |
3797 | (pass-if (documented? imag-part)) | |
c7218482 | 3798 | (pass-if (eqv? 0 (imag-part 5.0))) |
2519490c MW |
3799 | (pass-if (eqv? 5.0 (imag-part +5.0i))) |
3800 | (pass-if (eqv? 0 (imag-part 5))) | |
3801 | (pass-if (eqv? 0 (imag-part 1/5))) | |
3802 | (pass-if (eqv? 0 (imag-part (1+ fixnum-max))))) | |
3803 | ||
f29b3454 DH |
3804 | ;;; |
3805 | ;;; magnitude | |
3806 | ;;; | |
3807 | ||
d40681ec | 3808 | (with-test-prefix "magnitude" |
2519490c | 3809 | (pass-if (documented? magnitude)) |
d40681ec KR |
3810 | (pass-if (= 0 (magnitude 0))) |
3811 | (pass-if (= 1 (magnitude 1))) | |
3812 | (pass-if (= 1 (magnitude -1))) | |
3813 | (pass-if (= 1 (magnitude 0+i))) | |
3814 | (pass-if (= 1 (magnitude 0-i))) | |
3815 | (pass-if (= 5 (magnitude 3+4i))) | |
3816 | (pass-if (= 5 (magnitude 3-4i))) | |
3817 | (pass-if (= 5 (magnitude -3+4i))) | |
3818 | (pass-if (= 5 (magnitude -3-4i)))) | |
3819 | ||
f29b3454 DH |
3820 | ;;; |
3821 | ;;; angle | |
3822 | ;;; | |
3823 | ||
cfc9fc1c KR |
3824 | (with-test-prefix "angle" |
3825 | (define pi 3.14159265358979323846) | |
3826 | (define (almost= x y) | |
3827 | (> 0.01 (magnitude (- x y)))) | |
3828 | ||
2519490c MW |
3829 | (pass-if (documented? angle)) |
3830 | ||
cfc9fc1c KR |
3831 | (pass-if "inum +ve" (= 0 (angle 1))) |
3832 | (pass-if "inum -ve" (almost= pi (angle -1))) | |
3833 | ||
3834 | (pass-if "bignum +ve" (= 0 (angle (1+ fixnum-max)))) | |
3835 | (pass-if "bignum -ve" (almost= pi (angle (1- fixnum-min)))) | |
3836 | ||
3837 | (pass-if "flonum +ve" (= 0 (angle 1.5))) | |
3838 | (pass-if "flonum -ve" (almost= pi (angle -1.5)))) | |
3839 | ||
f29b3454 DH |
3840 | ;;; |
3841 | ;;; inexact->exact | |
3842 | ;;; | |
300c6a76 | 3843 | |
1259cb26 | 3844 | (with-test-prefix "inexact->exact" |
2519490c MW |
3845 | (pass-if (documented? inexact->exact)) |
3846 | ||
9dd9857f | 3847 | (pass-if-exception "+inf" exception:out-of-range |
a409f865 | 3848 | (inexact->exact +inf.0)) |
1259cb26 | 3849 | |
9dd9857f | 3850 | (pass-if-exception "-inf" exception:out-of-range |
a409f865 | 3851 | (inexact->exact -inf.0)) |
1259cb26 | 3852 | |
9dd9857f | 3853 | (pass-if-exception "nan" exception:out-of-range |
a409f865 | 3854 | (inexact->exact +nan.0)) |
1259cb26 KR |
3855 | |
3856 | (with-test-prefix "2.0**i to exact and back" | |
3857 | (do ((i 0 (1+ i)) | |
3858 | (n 1.0 (* 2.0 n))) | |
3859 | ((> i 100)) | |
3860 | (pass-if (list i n) | |
3861 | (= n (inexact->exact (exact->inexact n))))))) | |
3862 | ||
c1122753 KR |
3863 | ;;; |
3864 | ;;; integer-expt | |
3865 | ;;; | |
3866 | ||
3867 | (with-test-prefix "integer-expt" | |
2519490c | 3868 | (pass-if (documented? integer-expt)) |
c1122753 KR |
3869 | |
3870 | (pass-if-exception "2^+inf" exception:wrong-type-arg | |
3871 | (integer-expt 2 +inf.0)) | |
3872 | (pass-if-exception "2^-inf" exception:wrong-type-arg | |
3873 | (integer-expt 2 -inf.0)) | |
3874 | (pass-if-exception "2^nan" exception:wrong-type-arg | |
01c7284a MW |
3875 | (integer-expt 2 +nan.0)) |
3876 | ||
3877 | (pass-if (eqv? 1 (integer-expt 0 0))) | |
3878 | (pass-if (eqv? 1 (integer-expt 0.0 0))) | |
55a8b708 MW |
3879 | (pass-if (real-nan? (integer-expt 0 -1))) |
3880 | (pass-if (real-nan? (integer-expt 0.0 -1))) | |
01c7284a MW |
3881 | (pass-if (eqv? 0 (integer-expt 0 3))) |
3882 | (pass-if (eqv? 0.0 (integer-expt 0.0 5))) | |
3883 | (pass-if (eqv? -2742638075.5 (integer-expt -2742638075.5 1))) | |
3884 | (pass-if (eqv? (* -2742638075.5 -2742638075.5) | |
3885 | (integer-expt -2742638075.5 2))) | |
3886 | (pass-if (eqv? 4.0 (integer-expt -2.0 2))) | |
3887 | (pass-if (eqv? -1/8 (integer-expt -2 -3))) | |
3888 | (pass-if (eqv? -0.125 (integer-expt -2.0 -3))) | |
3889 | (pass-if (eqv? 0.25 (integer-expt 2.0 -2))) | |
c7218482 | 3890 | (pass-if (test-eqv? (* -1.0+0.0i 12398 12398) (integer-expt +12398.0i 2)))) |
01c7284a | 3891 | |
c1122753 | 3892 | |
a04a3604 KR |
3893 | ;;; |
3894 | ;;; integer-length | |
3895 | ;;; | |
3896 | ||
3897 | (with-test-prefix "integer-length" | |
2519490c | 3898 | (pass-if (documented? integer-length)) |
a04a3604 KR |
3899 | |
3900 | (with-test-prefix "-2^i, ...11100..00" | |
3901 | (do ((n -1 (ash n 1)) | |
3902 | (i 0 (1+ i))) | |
3903 | ((> i 256)) | |
3904 | (pass-if (list n "expect" i) | |
3905 | (= i (integer-length n))))) | |
3906 | ||
3907 | (with-test-prefix "-2^i+1 ...11100..01" | |
3908 | (do ((n -3 (logxor 3 (ash n 1))) | |
3909 | (i 2 (1+ i))) | |
3910 | ((> i 256)) | |
3911 | (pass-if n | |
3912 | (= i (integer-length n))))) | |
3913 | ||
3914 | (with-test-prefix "-2^i-1 ...111011..11" | |
3915 | (do ((n -2 (1+ (ash n 1))) | |
3916 | (i 1 (1+ i))) | |
3917 | ((> i 256)) | |
3918 | (pass-if n | |
3919 | (= i (integer-length n)))))) | |
3920 | ||
8ab3d8a0 KR |
3921 | ;;; |
3922 | ;;; log | |
3923 | ;;; | |
3924 | ||
3925 | (with-test-prefix "log" | |
2519490c | 3926 | (pass-if (documented? log)) |
8ab3d8a0 KR |
3927 | |
3928 | (pass-if-exception "no args" exception:wrong-num-args | |
3929 | (log)) | |
3930 | (pass-if-exception "two args" exception:wrong-num-args | |
3931 | (log 123 456)) | |
3932 | ||
3933 | (pass-if (negative-infinity? (log 0))) | |
3934 | (pass-if (negative-infinity? (log 0.0))) | |
3935 | (pass-if (eqv? 0.0 (log 1))) | |
3936 | (pass-if (eqv? 0.0 (log 1.0))) | |
3937 | (pass-if (eqv-loosely? 1.0 (log const-e))) | |
3938 | (pass-if (eqv-loosely? 2.0 (log const-e^2))) | |
3939 | (pass-if (eqv-loosely? -1.0 (log const-1/e))) | |
3940 | ||
3941 | (pass-if (eqv-loosely? 1.0+1.57079i (log 0+2.71828i))) | |
3942 | (pass-if (eqv-loosely? 1.0-1.57079i (log 0-2.71828i))) | |
3943 | ||
3944 | (pass-if (eqv-loosely? 0.0+3.14159i (log -1.0))) | |
3945 | (pass-if (eqv-loosely? 1.0+3.14159i (log -2.71828))) | |
3946 | (pass-if (eqv-loosely? 2.0+3.14159i (log (* -2.71828 2.71828))))) | |
3947 | ||
3948 | ;;; | |
3949 | ;;; log10 | |
3950 | ;;; | |
3951 | ||
3952 | (with-test-prefix "log10" | |
2519490c | 3953 | (pass-if (documented? log10)) |
8ab3d8a0 KR |
3954 | |
3955 | (pass-if-exception "no args" exception:wrong-num-args | |
3956 | (log10)) | |
3957 | (pass-if-exception "two args" exception:wrong-num-args | |
3958 | (log10 123 456)) | |
3959 | ||
3960 | (pass-if (negative-infinity? (log10 0))) | |
3961 | (pass-if (negative-infinity? (log10 0.0))) | |
3962 | (pass-if (eqv? 0.0 (log10 1))) | |
3963 | (pass-if (eqv? 0.0 (log10 1.0))) | |
3964 | (pass-if (eqv-loosely? 1.0 (log10 10.0))) | |
3965 | (pass-if (eqv-loosely? 2.0 (log10 100.0))) | |
3966 | (pass-if (eqv-loosely? -1.0 (log10 0.1))) | |
3967 | ||
3968 | (pass-if (eqv-loosely? 1.0+0.68218i (log10 0+10.0i))) | |
3969 | (pass-if (eqv-loosely? 1.0-0.68218i (log10 0-10.0i))) | |
3970 | ||
3971 | (pass-if (eqv-loosely? 0.0+1.36437i (log10 -1))) | |
3972 | (pass-if (eqv-loosely? 1.0+1.36437i (log10 -10))) | |
3973 | (pass-if (eqv-loosely? 2.0+1.36437i (log10 -100)))) | |
3974 | ||
abff733b KR |
3975 | ;;; |
3976 | ;;; logbit? | |
3977 | ;;; | |
3978 | ||
3979 | (with-test-prefix "logbit?" | |
2519490c MW |
3980 | (pass-if (documented? logbit?)) |
3981 | ||
abff733b KR |
3982 | (pass-if (eq? #f (logbit? 0 0))) |
3983 | (pass-if (eq? #f (logbit? 1 0))) | |
3984 | (pass-if (eq? #f (logbit? 31 0))) | |
3985 | (pass-if (eq? #f (logbit? 32 0))) | |
3986 | (pass-if (eq? #f (logbit? 33 0))) | |
3987 | (pass-if (eq? #f (logbit? 63 0))) | |
3988 | (pass-if (eq? #f (logbit? 64 0))) | |
3989 | (pass-if (eq? #f (logbit? 65 0))) | |
3990 | ||
3991 | ;; prior to guile 1.6.5, testing bit 32, 64 etc of value 1 would wrap | |
3992 | ;; around and return #t where it ought to be #f | |
3993 | (pass-if (eq? #t (logbit? 0 1))) | |
3994 | (pass-if (eq? #f (logbit? 1 1))) | |
3995 | (pass-if (eq? #f (logbit? 31 1))) | |
3996 | (pass-if (eq? #f (logbit? 32 1))) | |
3997 | (pass-if (eq? #f (logbit? 33 1))) | |
3998 | (pass-if (eq? #f (logbit? 63 1))) | |
3999 | (pass-if (eq? #f (logbit? 64 1))) | |
4000 | (pass-if (eq? #f (logbit? 65 1))) | |
4001 | (pass-if (eq? #f (logbit? 128 1))) | |
4002 | ||
4003 | (pass-if (eq? #t (logbit? 0 -1))) | |
4004 | (pass-if (eq? #t (logbit? 1 -1))) | |
4005 | (pass-if (eq? #t (logbit? 31 -1))) | |
4006 | (pass-if (eq? #t (logbit? 32 -1))) | |
4007 | (pass-if (eq? #t (logbit? 33 -1))) | |
4008 | (pass-if (eq? #t (logbit? 63 -1))) | |
4009 | (pass-if (eq? #t (logbit? 64 -1))) | |
4010 | (pass-if (eq? #t (logbit? 65 -1)))) | |
4011 | ||
300c6a76 KR |
4012 | ;;; |
4013 | ;;; logcount | |
4014 | ;;; | |
4015 | ||
4016 | (with-test-prefix "logcount" | |
2519490c | 4017 | (pass-if (documented? logcount)) |
300c6a76 KR |
4018 | |
4019 | (with-test-prefix "-2^i, meaning ...11100..00" | |
4020 | (do ((n -1 (ash n 1)) | |
4021 | (i 0 (1+ i))) | |
4022 | ((> i 256)) | |
795c0bae KR |
4023 | (pass-if n |
4024 | (= i (logcount n))))) | |
4025 | ||
4026 | (with-test-prefix "2^i" | |
4027 | (do ((n 1 (ash n 1)) | |
4028 | (i 0 (1+ i))) | |
4029 | ((> i 256)) | |
4030 | (pass-if n | |
4031 | (= 1 (logcount n))))) | |
4032 | ||
4033 | (with-test-prefix "2^i-1" | |
4034 | (do ((n 0 (1+ (ash n 1))) | |
4035 | (i 0 (1+ i))) | |
4036 | ((> i 256)) | |
300c6a76 KR |
4037 | (pass-if n |
4038 | (= i (logcount n)))))) | |
795c0bae | 4039 | |
afd09cfb KR |
4040 | ;;; |
4041 | ;;; logior | |
4042 | ;;; | |
4043 | ||
4044 | (with-test-prefix "logior" | |
2519490c MW |
4045 | (pass-if (documented? logior)) |
4046 | ||
afd09cfb KR |
4047 | (pass-if (eqv? -1 (logior (ash -1 1) 1))) |
4048 | ||
4049 | ;; check that bignum or bignum+inum args will reduce to an inum | |
4050 | (let () | |
4051 | (define (test x y) | |
4052 | (pass-if (list x y '=> -1) | |
4053 | (eqv? -1 (logior x y))) | |
4054 | (pass-if (list y x '=> -1) | |
4055 | (eqv? -1 (logior y x)))) | |
4056 | (test (ash -1 8) #xFF) | |
4057 | (test (ash -1 28) #x0FFFFFFF) | |
4058 | (test (ash -1 29) #x1FFFFFFF) | |
4059 | (test (ash -1 30) #x3FFFFFFF) | |
4060 | (test (ash -1 31) #x7FFFFFFF) | |
4061 | (test (ash -1 32) #xFFFFFFFF) | |
4062 | (test (ash -1 33) #x1FFFFFFFF) | |
4063 | (test (ash -1 60) #x0FFFFFFFFFFFFFFF) | |
4064 | (test (ash -1 61) #x1FFFFFFFFFFFFFFF) | |
4065 | (test (ash -1 62) #x3FFFFFFFFFFFFFFF) | |
4066 | (test (ash -1 63) #x7FFFFFFFFFFFFFFF) | |
4067 | (test (ash -1 64) #xFFFFFFFFFFFFFFFF) | |
4068 | (test (ash -1 65) #x1FFFFFFFFFFFFFFFF) | |
4069 | (test (ash -1 128) #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))) | |
4070 | ||
1ec2dd6f KR |
4071 | ;;; |
4072 | ;;; lognot | |
4073 | ;;; | |
4074 | ||
4075 | (with-test-prefix "lognot" | |
2519490c MW |
4076 | (pass-if (documented? lognot)) |
4077 | ||
1ec2dd6f KR |
4078 | (pass-if (= -1 (lognot 0))) |
4079 | (pass-if (= 0 (lognot -1))) | |
4080 | (pass-if (= -2 (lognot 1))) | |
4081 | (pass-if (= 1 (lognot -2))) | |
4082 | ||
4083 | (pass-if (= #x-100000000000000000000000000000000 | |
4084 | (lognot #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF))) | |
4085 | (pass-if (= #xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF | |
4086 | (lognot #x-100000000000000000000000000000000)))) | |
8ab3d8a0 KR |
4087 | |
4088 | ;;; | |
4089 | ;;; sqrt | |
4090 | ;;; | |
4091 | ||
4092 | (with-test-prefix "sqrt" | |
2519490c | 4093 | (pass-if (documented? sqrt)) |
8ab3d8a0 KR |
4094 | |
4095 | (pass-if-exception "no args" exception:wrong-num-args | |
4096 | (sqrt)) | |
4097 | (pass-if-exception "two args" exception:wrong-num-args | |
4098 | (sqrt 123 456)) | |
4099 | ||
4100 | (pass-if (eqv? 0.0 (sqrt 0))) | |
4101 | (pass-if (eqv? 0.0 (sqrt 0.0))) | |
4102 | (pass-if (eqv? 1.0 (sqrt 1.0))) | |
4103 | (pass-if (eqv-loosely? 2.0 (sqrt 4.0))) | |
4104 | (pass-if (eqv-loosely? 31.62 (sqrt 1000.0))) | |
4105 | ||
4106 | (pass-if (eqv? +1.0i (sqrt -1.0))) | |
4107 | (pass-if (eqv-loosely? +2.0i (sqrt -4.0))) | |
4108 | (pass-if (eqv-loosely? +31.62i (sqrt -1000.0))) | |
4109 | ||
4110 | (pass-if "+i swings back to 45deg angle" | |
4111 | (eqv-loosely? +0.7071+0.7071i (sqrt +1.0i))) | |
4112 | ||
4113 | ;; Note: glibc 2.3 csqrt() had a bug affecting this test case, so if it | |
4114 | ;; fails check whether that's the cause (there's a configure test to | |
4115 | ;; reject it, but when cross-compiling we assume the C library is ok). | |
4116 | (pass-if "-100i swings back to 45deg down" | |
4117 | (eqv-loosely? +7.071-7.071i (sqrt -100.0i)))) | |
4118 | ||
ff62c168 MW |
4119 | ;;; |
4120 | ;;; euclidean/ | |
4121 | ;;; euclidean-quotient | |
4122 | ;;; euclidean-remainder | |
4123 | ;;; centered/ | |
4124 | ;;; centered-quotient | |
4125 | ;;; centered-remainder | |
4126 | ;;; | |
4127 | ||
4128 | (with-test-prefix "Number-theoretic division" | |
4129 | ||
4130 | ;; Tests that (lo <= x < hi), | |
4131 | ;; but allowing for imprecision | |
4132 | ;; if x is inexact. | |
4133 | (define (test-within-range? lo hi x) | |
4134 | (if (exact? x) | |
4135 | (and (<= lo x) (< x hi)) | |
4136 | (let ((lo (- lo test-epsilon)) | |
4137 | (hi (+ hi test-epsilon))) | |
4138 | (<= lo x hi)))) | |
4139 | ||
a8591a55 MW |
4140 | ;; (cartesian-product-map list '(a b) '(1 2)) |
4141 | ;; ==> ((a 1) (a 2) (b 1) (b 2)) | |
4142 | (define (cartesian-product-map f . lsts) | |
4143 | (define (cartmap rev-head lsts) | |
4144 | (if (null? lsts) | |
4145 | (list (apply f (reverse rev-head))) | |
4146 | (append-map (lambda (x) (cartmap (cons x rev-head) (cdr lsts))) | |
4147 | (car lsts)))) | |
4148 | (cartmap '() lsts)) | |
4149 | ||
4150 | (define (cartesian-product-for-each f . lsts) | |
4151 | (define (cartfor rev-head lsts) | |
4152 | (if (null? lsts) | |
4153 | (apply f (reverse rev-head)) | |
4154 | (for-each (lambda (x) (cartfor (cons x rev-head) (cdr lsts))) | |
4155 | (car lsts)))) | |
4156 | (cartfor '() lsts)) | |
4157 | ||
ff62c168 MW |
4158 | (define (safe-euclidean-quotient x y) |
4159 | (cond ((not (and (real? x) (real? y))) (throw 'wrong-type-arg)) | |
4160 | ((zero? y) (throw 'divide-by-zero)) | |
4161 | ((nan? y) (nan)) | |
4162 | ((positive? y) (floor (/ x y))) | |
4163 | ((negative? y) (ceiling (/ x y))) | |
4164 | (else (throw 'unknown-problem)))) | |
4165 | ||
4166 | (define (safe-euclidean-remainder x y) | |
a8591a55 MW |
4167 | (let ((q (safe-euclidean-quotient x y))) |
4168 | (- x (* y q)))) | |
4169 | ||
4170 | (define (valid-euclidean-answer? x y q r) | |
4171 | (if (and (finite? x) (finite? y)) | |
4172 | (and (eq? (exact? q) | |
4173 | (exact? r) | |
4174 | (and (exact? x) (exact? y))) | |
4175 | (integer? q) | |
4176 | (test-eqv? r (- x (* q y))) | |
4177 | (test-within-range? 0 (abs y) r)) | |
4178 | (and (test-eqv? q (safe-euclidean-quotient x y)) | |
4179 | (test-eqv? r (safe-euclidean-remainder x y))))) | |
ff62c168 MW |
4180 | |
4181 | (define (safe-centered-quotient x y) | |
4182 | (cond ((not (and (real? x) (real? y))) (throw 'wrong-type-arg)) | |
4183 | ((zero? y) (throw 'divide-by-zero)) | |
4184 | ((nan? y) (nan)) | |
4185 | ((positive? y) (floor (+ 1/2 (/ x y)))) | |
4186 | ((negative? y) (ceiling (+ -1/2 (/ x y)))) | |
4187 | (else (throw 'unknown-problem)))) | |
4188 | ||
4189 | (define (safe-centered-remainder x y) | |
a8591a55 MW |
4190 | (let ((q (safe-centered-quotient x y))) |
4191 | (- x (* y q)))) | |
4192 | ||
4193 | (define (valid-centered-answer? x y q r) | |
4194 | (if (and (finite? x) (finite? y)) | |
4195 | (and (eq? (exact? q) | |
4196 | (exact? r) | |
4197 | (and (exact? x) (exact? y))) | |
4198 | (integer? q) | |
4199 | (test-eqv? r (- x (* q y))) | |
4200 | (test-within-range? (* -1/2 (abs y)) | |
4201 | (* +1/2 (abs y)) | |
4202 | r)) | |
4203 | (and (test-eqv? q (safe-centered-quotient x y)) | |
4204 | (test-eqv? r (safe-centered-remainder x y))))) | |
ff62c168 MW |
4205 | |
4206 | (define test-numerators | |
a8591a55 MW |
4207 | (append (cartesian-product-map * '(1 -1) |
4208 | '(123 125 127 130 3 5 10 | |
4209 | 123.2 125.0 127.2 130.0 | |
4210 | 123/7 125/7 127/7 130/7)) | |
4211 | (cartesian-product-map * '(1 -1) | |
4212 | '(123 125 127 130 3 5 10) | |
4213 | (list 1 | |
4214 | (+ 1 most-positive-fixnum) | |
4215 | (+ 2 most-positive-fixnum))) | |
4216 | (list 0 +0.0 -0.0 +inf.0 -inf.0 +nan.0 | |
4217 | most-negative-fixnum | |
4218 | (1+ most-positive-fixnum) | |
4219 | (1- most-negative-fixnum)))) | |
ff62c168 MW |
4220 | |
4221 | (define test-denominators | |
4222 | (list 10 5 10/7 127/2 10.0 63.5 | |
4223 | -10 -5 -10/7 -127/2 -10.0 -63.5 | |
4224 | +inf.0 -inf.0 +nan.0 most-negative-fixnum | |
4225 | (+ 1 most-positive-fixnum) (+ -1 most-negative-fixnum) | |
4226 | (+ 2 most-positive-fixnum) (+ -2 most-negative-fixnum))) | |
4227 | ||
ff62c168 | 4228 | (with-test-prefix "euclidean/" |
a8591a55 MW |
4229 | (pass-if (documented? euclidean/)) |
4230 | (pass-if (documented? euclidean-quotient)) | |
4231 | (pass-if (documented? euclidean-remainder)) | |
4232 | ||
4233 | (cartesian-product-for-each | |
4234 | (lambda (n d) | |
4235 | (run-test (list 'euclidean/ n d) #t | |
4236 | (lambda () | |
4237 | (let-values (((q r) (euclidean/ n d))) | |
4238 | (and (test-eqv? q (euclidean-quotient n d)) | |
4239 | (test-eqv? r (euclidean-remainder n d)) | |
4240 | (valid-euclidean-answer? n d q r)))))) | |
4241 | test-numerators test-denominators)) | |
4242 | ||
ff62c168 | 4243 | (with-test-prefix "centered/" |
a8591a55 MW |
4244 | (pass-if (documented? centered/)) |
4245 | (pass-if (documented? centered-quotient)) | |
4246 | (pass-if (documented? centered-remainder)) | |
4247 | ||
4248 | (cartesian-product-for-each | |
4249 | (lambda (n d) | |
4250 | (run-test (list 'centered/ n d) #t | |
4251 | (lambda () | |
4252 | (let-values (((q r) (centered/ n d))) | |
4253 | (and (test-eqv? q (centered-quotient n d)) | |
4254 | (test-eqv? r (centered-remainder n d)) | |
4255 | (valid-centered-answer? n d q r)))))) | |
4256 | test-numerators test-denominators))) |