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