Debian Codegraph @

test/include/srfi-144-tests.scm

raw
1 ;;; Copyright (C) William D Clinger (2017).
2 ;;;
3 ;;; Permission is hereby granted, free of charge, to any person
4 ;;; obtaining a copy of this software and associated documentation
5 ;;; files (the "Software"), to deal in the Software without
6 ;;; restriction, including without limitation the rights to use,
7 ;;; copy, modify, merge, publish, distribute, sublicense, and/or
8 ;;; sell copies of the Software, and to permit persons to whom the
9 ;;; Software is furnished to do so, subject to the following
10 ;;; conditions:
11 ;;;
12 ;;; The above copyright notice and this permission notice shall be
13 ;;; included in all copies or substantial portions of the Software.
14 ;;;
15 ;;; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 ;;; EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
17 ;;; OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 ;;; NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
19 ;;; HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
20 ;;; WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
21 ;;; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 ;;; OTHER DEALINGS IN THE SOFTWARE.
23
24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
25 ;;;
26 ;;; Tests these (srfi 144) constants and procedures:
27 ;;;
28 ;;; fl-e
29 ;;; fl-1/e
30 ;;; fl-e-2
31 ;;; fl-e-pi/4
32 ;;; fl-log2-e
33 ;;; fl-log10-e
34 ;;; fl-log-2
35 ;;; fl-1/log-2
36 ;;; fl-log-3
37 ;;; fl-log-pi
38 ;;; fl-log-10
39 ;;; fl-1/log-10
40 ;;; fl-pi
41 ;;; fl-1/pi
42 ;;; fl-2pi
43 ;;; fl-pi/2
44 ;;; fl-pi/4
45 ;;; fl-2/sqrt-pi
46 ;;; fl-pi-squared
47 ;;; fl-degree
48 ;;; fl-2/pi
49 ;;; fl-sqrt-2
50 ;;; fl-sqrt-3
51 ;;; fl-sqrt-5
52 ;;; fl-sqrt-10
53 ;;; fl-1/sqrt-2
54 ;;; fl-cbrt-2
55 ;;; fl-cbrt-3
56 ;;; fl-4thrt-2
57 ;;; fl-phi
58 ;;; fl-log-phi
59 ;;; fl-1/log-phi
60 ;;; fl-euler
61 ;;; fl-e-euler
62 ;;; fl-sin-1
63 ;;; fl-cos-1
64 ;;; fl-gamma-1/2
65 ;;; fl-gamma-1/3
66 ;;; fl-gamma-2/3
67 ;;;
68 ;;; fl-greatest
69 ;;; fl-least
70 ;;; fl-epsilon
71 ;;; fl-fast-fl+*
72 ;;; fl-integer-exponent-zero
73 ;;; fl-integer-exponent-nan
74 ;;;
75 ;;; flonum
76 ;;; fladjacent
77 ;;; flcopysign
78 ;;; make-flonum
79 ;;;
80 ;;; flinteger-fraction
81 ;;; flexponent
82 ;;; flinteger-exponent
83 ;;; flnormalized-fraction-exponent
84 ;;; flsign-bit
85 ;;;
86 ;;; flonum?
87 ;;; fl=?
88 ;;; fl<?
89 ;;; fl>?
90 ;;; fl<=?
91 ;;; fl>=?
92 ;;; flunordered?
93 ;;; flmax
94 ;;; flmin
95 ;;; flinteger?
96 ;;; flzero?
97 ;;; flpositive?
98 ;;; flnegative?
99 ;;; flodd?
100 ;;; fleven?
101 ;;; flfinite?
102 ;;; flinfinite?
103 ;;; flnan?
104 ;;; flnormalized?
105 ;;; fldenormalized?
106 ;;;
107 ;;; fl+
108 ;;; fl*
109 ;;; fl+*
110 ;;; fl-
111 ;;; fl/
112 ;;; flabs
113 ;;; flabsdiff
114 ;;; flposdiff
115 ;;; flsgn
116 ;;; flnumerator
117 ;;; fldenominator
118 ;;; flfloor
119 ;;; flceiling
120 ;;; flround
121 ;;; fltruncate
122 ;;;
123 ;;; flexp
124 ;;; flexp2
125 ;;; flexp-1
126 ;;; flsquare
127 ;;; flsqrt
128 ;;; flcbrt
129 ;;; flhypot
130 ;;; flexpt
131 ;;; fllog
132 ;;; fllog1+
133 ;;; fllog2
134 ;;; fllog10
135 ;;; make-fllog-base
136 ;;;
137 ;;; flsin
138 ;;; flcos
139 ;;; fltan
140 ;;; flasin
141 ;;; flacos
142 ;;; flatan
143 ;;; flsinh
144 ;;; flcosh
145 ;;; fltanh
146 ;;; flasinh
147 ;;; flacosh
148 ;;; flatanh
149 ;;;
150 ;;; flquotient
151 ;;; flremainder
152 ;;; flremquo
153 ;;;
154 ;;; flgamma
155 ;;; flloggamma
156 ;;; flfirst-bessel
157 ;;; flsecond-bessel
158 ;;; flerf
159 ;;; flerfc
160
161
162 (define-library (tests scheme flonum)
163 (export run-flonum-tests)
164 (import (scheme base)
165 (srfi 144)
166 (tests scheme test)
167 (scheme inexact))
168
169 (cond-expand
170 ((library (scheme list))
171 (import (only (scheme list) filter iota)))
172 ((library (srfi 1))
173 (import (only (srfi 1) filter iota)))
174 (else
175 (begin
176 (define (filter p? x)
177 (cond ((null? x) x)
178 ((p? (car x)) (cons (car x) (filter p? (cdr x))))
179 (else (filter p? (cdr x)))))
180 (define (iota n)
181 (do ((n (- n 1) (- n 1))
182 (x '() (cons n x)))
183 ((< n 0) x))))))
184
185 (begin
186
187 (define-syntax test-assert
188 (syntax-rules ()
189 ((test-assert expr)
190 (test expr #t))))
191
192 (define-syntax test-deny
193 (syntax-rules ()
194 ((test-assert expr)
195 (test expr #f))))
196
197 (define-syntax test-error
198 (syntax-rules ()
199 ((test-error expr)
200 (test/unspec-or-exn expr &error))))
201
202 (define-syntax test/=
203 (syntax-rules ()
204 ((test/= expr1 expr2)
205 (test expr2 expr1))))
206
207 ;; convenient values for test cases
208
209 (define posints (map flonum '(1 2 3 4 5 10 65536 1e23)))
210 (define nats (cons (flonum 0) posints))
211 (define ints (append (map flonum '(-20 -8 -2 -1)) nats))
212 (define posfracs (map flonum '(1/1000 1/10 1/3 1/2)))
213 (define extremes
214 (list (fl- fl-greatest) (fl- fl-least) fl-least fl-greatest))
215 (define infinities (map flonum (list -inf.0 +inf.0)))
216 (define weird (append infinities (list (flonum +nan.0))))
217
218 (define somereals (append (map flonum
219 (list (fl- fl-greatest)
220 -10
221 (fl- fl-least)
222 0))
223 posfracs
224 posints))
225 (define somereals+weird
226 (append somereals weird))
227
228 (define negzero (flonum -0.0))
229 (define zero (flonum 0))
230 (define one (flonum 1))
231 (define two (flonum 2))
232
233 (define neginf (flonum -inf.0))
234 (define posinf (flonum +inf.0))
235 (define nan (flonum +nan.0))
236
237
238 (define (run-flonum-tests)
239
240 ;; Mathematical constants
241
242 (test/= 2.718281828459045235360287 fl-e)
243 (test/= .3678794411714423215955238 fl-1/e)
244 (test/= 7.389056098930650227230427 fl-e-2)
245 (test/= 2.1932800507380154566 fl-e-pi/4)
246 (test/= 1.4426950408889634073599246810018921374266 fl-log2-e)
247 (test/= .4342944819032518276511289 fl-log10-e)
248 (test/= .6931471805599453094172321 fl-log-2)
249 (test/= 1.4426950408889634073599246810018921374266 fl-1/log-2)
250 ;; [SK] MUSL clib yields 1ulp error
251 ;;(test/= 1.0986122886681096913952452 fl-log-3)
252 (test/approx-1ulp 1.0986122886681096913952452 fl-log-3)
253 (test/= 1.144729885849400174143427 fl-log-pi)
254 (test/= 2.3025850929940456840179915 fl-log-10)
255 (test/= 0.4342944819032518276511289189166050822944 fl-1/log-10)
256
257 (test/= 3.1415926535897932384626433832795028841972 fl-pi)
258 (test/= 0.3183098861837906715377675267450287240689 fl-1/pi)
259 (test/= 6.283185307179586476925287 fl-2pi)
260 (test/= 1.570796326794896619231322 fl-pi/2)
261 (test/= .7853981633974483096156608 fl-pi/4)
262 (test/= .5641895835477562869480795 (/ fl-2/sqrt-pi 2))
263 (test/= 9.869604401089358618834491 fl-pi-squared)
264 (test/= 0.0174532925199432957692369076848861271344 fl-degree)
265 (test/= .3183098861837906715377675 (/ fl-2/pi 2))
266
267 (test/= 1.4142135623730950488016887242096980785697 fl-sqrt-2)
268 (test/= 1.7320508075688772935274463415058723669428 fl-sqrt-3)
269 (test/= 2.2360679774997896964091736687311762354406 fl-sqrt-5)
270 (test/= 3.1622776601683793319988935444327185337196 fl-sqrt-10)
271 ;; [SK] The following yields 1ulp error in 64bit precision
272 ;;(test/= 1.4142135623730950488016887242096980785697 (* 2 fl-1/sqrt-2))
273 (test/approx-1ulp 1.4142135623730950488016887242096980785697 (* 2 fl-1/sqrt-2))
274 (test/= 1.2599210498948731647672106072782283505703 fl-cbrt-2)
275 (test/= 1.4422495703074083823216383107801095883919 fl-cbrt-3)
276 (test/= 1.1892071150027210667174999705604759152930 fl-4thrt-2)
277
278 (test/= 1.6180339887498948482045868343656381177203 fl-phi)
279 (test/= 0.4812118250596034474977589134243684231352 fl-log-phi)
280 (test/= 2.0780869212350275376013226061177957677422 fl-1/log-phi)
281 (test/= 0.5772156649015328606065120900824024310422 fl-euler)
282 (test/= 1.7810724179901979852365041031071795491696 fl-e-euler)
283
284 (test/= 0.8414709848078965066525023216302989996226 fl-sin-1)
285 (test/= 0.5403023058681397174009366074420766037323 fl-cos-1)
286
287 (test/= 1.7724538509055160272981674833411451827975 fl-gamma-1/2)
288 (test/= 2.6789385347077476336556929409746776441287 fl-gamma-1/3)
289 ;; [SK] MUSL clib yields 1ulp error
290 ;;(test/= 1.3541179394264004169452880281545137855193 fl-gamma-2/3)
291 (test/approx-1ulp 1.3541179394264004169452880281545137855193 fl-gamma-2/3)
292 ;; Implementation Constants
293
294 (test-assert (inexact? fl-greatest))
295 (test-assert (inexact? fl-least))
296 (test-assert (inexact? fl-epsilon))
297
298 (test-assert (real? fl-greatest))
299 (test-assert (real? fl-least))
300 (test-assert (real? fl-epsilon))
301
302 (test-assert (flonum? fl-greatest))
303 (test-assert (flonum? fl-least))
304 (test-assert (flonum? fl-epsilon))
305
306 (test-assert (< 0.0
307 fl-least
308 fl-epsilon
309 1.0
310 (+ 1.0 fl-epsilon)
311 fl-greatest
312 posinf))
313 (test-assert (= (* 2 fl-greatest) posinf))
314 (test-assert (= 1 (/ (+ 1 (+ 1.0 fl-epsilon)) 2)))
315 (test-assert (= 0.0 (/ fl-least 2)))
316
317 (test-assert (boolean? fl-fast-fl+*))
318 (test-assert (exact-integer? fl-integer-exponent-zero))
319 (test-assert (exact-integer? fl-integer-exponent-nan))
320
321 ;; Constructors
322
323 (test (flonum 3) (flonum 3.0))
324 (test (map flonum somereals) somereals)
325 (test (map flonum weird) weird)
326
327 (test (map fladjacent somereals somereals) somereals)
328 (test (map fladjacent weird weird) weird)
329
330 (test (fladjacent zero posinf) fl-least)
331 (test (fladjacent zero neginf) (fl- fl-least))
332 (test (fladjacent fl-least posinf) (fl+ fl-least fl-least))
333 (test (fladjacent fl-least neginf) zero)
334 (test (fladjacent (fl- fl-least) posinf) negzero)
335 (test (fladjacent (fl- fl-least) neginf) (fl* -2.0 fl-least))
336
337 (test (fladjacent zero one) fl-least)
338 (test (fladjacent zero (fl- one)) (fl- fl-least))
339 (test (fladjacent fl-least one) (fl+ fl-least fl-least))
340 (test (fladjacent fl-least (fl- one)) zero)
341 (test (fladjacent (fl- fl-least) one) negzero)
342 (test (fladjacent (fl- fl-least) (fl- one)) (fl* -2.0 fl-least))
343
344 (test (fl- (fladjacent one fl-greatest) one) fl-epsilon)
345 (test (fl- one (fladjacent one zero)) (fl/ fl-epsilon 2.0))
346
347 (test (fladjacent posinf zero) fl-greatest)
348 (test (fladjacent neginf zero) (fl- fl-greatest))
349
350 (test (flcopysign zero posinf) zero)
351 (test (flcopysign zero neginf) negzero)
352 (test (flcopysign zero one) zero)
353 (test (flcopysign zero (fl- one)) negzero)
354 (test (flcopysign one fl-least) one)
355 (test (flcopysign one (fl- fl-greatest)) (fl- one))
356 (test (flcopysign (fl- one) zero) one)
357 (test (map flcopysign somereals somereals) somereals)
358 (test (map flcopysign somereals (map fl- somereals))
359 (map fl- somereals))
360 (test (map flcopysign infinities infinities) infinities)
361 (test (map flcopysign infinities (reverse infinities))
362 (reverse infinities))
363
364 (test (make-flonum zero 12) zero)
365 (test (make-flonum zero -24) zero)
366 (test (make-flonum zero 0) zero)
367 (test (map make-flonum somereals (map (lambda (x) 0) somereals))
368 somereals)
369 (test (map make-flonum somereals (map (lambda (x) 2) somereals))
370 (map (lambda (x) (fl* (flonum 4) x)) somereals))
371 (test (map make-flonum somereals (map (lambda (x) -4) somereals))
372 (map (lambda (x) (fl/ x (flonum 16))) somereals))
373 (test (make-flonum fl-greatest 1) posinf)
374 (test (make-flonum (fl- fl-greatest) 1) neginf)
375 (test (make-flonum fl-greatest -1) (fl/ fl-greatest two))
376 (test (make-flonum (fl- fl-greatest) -1) (fl- (fl/ fl-greatest two)))
377 (test (make-flonum fl-least 1) (fl* two fl-least))
378 (test (make-flonum (fl- fl-least) 1) (fl- (fl* two fl-least)))
379 (test (make-flonum fl-least -1) zero)
380 (test (make-flonum (fl- fl-least) -1) negzero)
381
382 ;; Accessors
383
384 (call-with-values
385 (lambda () (flinteger-fraction 3.75))
386 (lambda (q r)
387 (test q (flonum 3))
388 (test r (flonum .75))))
389
390 (call-with-values
391 (lambda () (flinteger-fraction -3.75))
392 (lambda (q r)
393 (test q (flonum -3))
394 (test r (flonum -.75))))
395
396 (test/= (flonum 12.0)
397 (flexponent (flexpt two (flonum 12))))
398 (test/approx (flexponent (flexpt two (flonum 12.5)))
399 (flonum 12))
400 (test/= (flonum -5.0)
401 (flexponent (flexpt two (flonum -5))))
402 (test/approx (flexponent (flexpt two (flonum +4.5)))
403 (flonum +4))
404 (test/approx (flexponent (flexpt two (flonum -4.5)))
405 (flonum -5))
406
407 (test (flinteger-exponent (flexpt two (flonum 12))) 12)
408 (test (flinteger-exponent (flexpt two (flonum 12.5))) 12)
409 (test (flinteger-exponent (flexpt two (flonum -5))) -5)
410 (test (flinteger-exponent (flexpt two (flonum -4.5))) -5)
411
412 (let* ((correct?
413 (lambda (x y n)
414 (or (fl=? x (* y (expt two n)))
415 (fl=? x (* 4.00 y (expt two (- n 2))))
416 (fl=? x (* 0.25 y (expt two (+ n 2)))))))
417 (test-flnormalized-fraction-exponent
418 (lambda (x)
419 (call-with-values
420 (lambda () (flnormalized-fraction-exponent x))
421 (lambda (y n)
422 (list (flonum? y)
423 (exact-integer? n)
424 (fl<=? (flonum 0.5) (flabs y))
425 (fl<? (flabs y) one)
426 (correct? x y n)))))))
427 (test (test-flnormalized-fraction-exponent zero)
428 '(#t #t #f #t #t))
429 (test (test-flnormalized-fraction-exponent negzero)
430 '(#t #t #f #t #t))
431 (test (test-flnormalized-fraction-exponent one)
432 '(#t #t #t #t #t))
433 (test (test-flnormalized-fraction-exponent two)
434 '(#t #t #t #t #t))
435 (test (test-flnormalized-fraction-exponent fl-least)
436 '(#t #t #t #t #t))
437 (test (test-flnormalized-fraction-exponent fl-greatest)
438 '(#t #t #t #t #t))
439 (test (test-flnormalized-fraction-exponent (fl- fl-least))
440 '(#t #t #t #t #t))
441 (test (test-flnormalized-fraction-exponent (fl- fl-greatest))
442 '(#t #t #t #t #t))
443 ;; [SK] The spec is ambiguous for the following tests.
444 ;; frexp returns inf on inf arg. Ref impl returns 0.5,
445 ;; with huge exponent.
446 ;; (test (test-flnormalized-fraction-exponent posinf)
447 ;; '(#t #t #t #t #t))
448 ;; (test (test-flnormalized-fraction-exponent neginf)
449 ;; '(#t #t #t #t #t))
450 (test (test-flnormalized-fraction-exponent nan)
451 '(#t #t #f #f #f))
452
453 )
454
455 (test (flsign-bit one) 0)
456 (test (flsign-bit zero) 0)
457 (test (flsign-bit negzero) 1)
458 (test (flsign-bit (flonum -2)) 1)
459 (test (flsign-bit posinf) 0)
460 (test (flsign-bit neginf) 1)
461
462 ;; Predicates
463
464 (let ((alltrue (map (lambda (x) #t) somereals))
465 (allfalse (map (lambda (x) #f) somereals)))
466
467 (test (map flonum? somereals) alltrue)
468 (test (map flonum? weird) '(#t #t #t))
469
470 (test-deny (fl=? zero fl-least))
471 (test-assert (fl=? fl-least fl-least))
472 (test-deny (fl=? one fl-least))
473 (test-assert (fl=? neginf neginf))
474 (test-deny (fl=? neginf posinf))
475 (test-deny (fl=? posinf neginf))
476 (test-assert (fl=? posinf posinf))
477 (test-deny (fl=? zero nan))
478 (test-deny (fl=? nan one))
479 (test (map fl=? somereals somereals) alltrue)
480 (test (map fl=? somereals (cdr somereals)) (cdr allfalse))
481 (test (map fl=? (cdr somereals) somereals) (cdr allfalse))
482
483 (test-assert (fl<? zero fl-least))
484 (test-deny (fl<? fl-least fl-least))
485 (test-deny (fl<? one fl-least))
486 (test-deny (fl<? neginf neginf))
487 (test-assert (fl<? neginf posinf))
488 (test-deny (fl<? posinf neginf))
489 (test-deny (fl<? posinf posinf))
490 (test-deny (fl<? zero nan))
491 (test-deny (fl<? nan one))
492 (test (map fl<? somereals somereals) allfalse)
493 (test (map fl<? somereals (cdr somereals)) (cdr alltrue))
494 (test (map fl<? (cdr somereals) somereals) (cdr allfalse))
495
496 (test-deny (fl>? zero fl-least))
497 (test-deny (fl>? fl-least fl-least))
498 (test-assert (fl>? one fl-least))
499 (test-deny (fl>? neginf neginf))
500 (test-deny (fl>? neginf posinf))
501 (test-assert (fl>? posinf neginf))
502 (test-deny (fl>? posinf posinf))
503 (test-deny (fl>? zero nan))
504 (test-deny (fl>? nan one))
505 (test (map fl>? somereals somereals) allfalse)
506 (test (map fl>? somereals (cdr somereals)) (cdr allfalse))
507 (test (map fl>? (cdr somereals) somereals) (cdr alltrue))
508
509 (test-assert (fl<=? zero fl-least))
510 (test-assert (fl<=? fl-least fl-least))
511 (test-deny (fl<=? one fl-least))
512 (test-assert (fl<=? neginf neginf))
513 (test-assert (fl<=? neginf posinf))
514 (test-deny (fl<=? posinf neginf))
515 (test-assert (fl<=? posinf posinf))
516 (test-deny (fl<=? zero nan))
517 (test-deny (fl<=? nan one))
518 (test (map fl<=? somereals somereals) alltrue)
519 (test (map fl<=? somereals (cdr somereals)) (cdr alltrue))
520 (test (map fl<=? (cdr somereals) somereals) (cdr allfalse))
521
522 (test-deny (fl>=? zero fl-least))
523 (test-assert (fl>=? fl-least fl-least))
524 (test-assert (fl>=? one fl-least))
525 (test-assert (fl>=? neginf neginf))
526 (test-deny (fl>=? neginf posinf))
527 (test-assert (fl>=? posinf neginf))
528 (test-assert (fl>=? posinf posinf))
529 (test-deny (fl>=? zero nan))
530 (test-deny (fl>=? nan one))
531 (test (map fl>=? somereals somereals) alltrue)
532 (test (map fl>=? somereals (cdr somereals)) (cdr allfalse))
533 (test (map fl>=? (cdr somereals) somereals) (cdr alltrue))
534
535 (test-deny (flunordered? zero fl-least))
536 (test-deny (flunordered? fl-least fl-least))
537 (test-deny (flunordered? one fl-least))
538 (test-deny (flunordered? neginf neginf))
539 (test-deny (flunordered? neginf posinf))
540 (test-deny (flunordered? posinf neginf))
541 (test-deny (flunordered? posinf posinf))
542 (test-assert (flunordered? zero nan))
543 (test-assert (flunordered? nan one))
544 (test (map flunordered? somereals somereals) allfalse)
545 (test (map flunordered? somereals (cdr somereals)) (cdr allfalse))
546 (test (map flunordered? (cdr somereals) somereals) (cdr allfalse))
547
548 )
549
550 (test (flmax) neginf)
551 (test (flmax zero) zero)
552 (test (flmax zero one) one)
553 (test (flmax one zero) one)
554 (test (apply flmax somereals) (car (reverse somereals)))
555
556 (test (flmin) posinf)
557 (test (flmin one) one)
558 (test (flmin zero one) zero)
559 (test (flmin one zero) zero)
560 (test (apply flmin somereals) (car somereals))
561
562 (test (map flinteger? somereals)
563 (map fl=?
564 somereals
565 (map flround somereals)))
566
567 (test-deny (flzero? neginf))
568 (test-deny (flzero? (fl- fl-least)))
569 (test-assert (flzero? negzero))
570 (test-assert (flzero? zero))
571 (test-deny (flzero? fl-least))
572 (test-deny (flzero? posinf))
573
574 (test-deny (flpositive? neginf))
575 (test-deny (flpositive? (fl- fl-least)))
576 (test-deny (flpositive? negzero))
577 (test-deny (flpositive? zero))
578 (test-assert (flpositive? fl-least))
579 (test-assert (flpositive? posinf))
580
581 (test-assert (flnegative? neginf))
582 (test-assert (flnegative? (fl- fl-least)))
583 (test-deny (flnegative? negzero)) ; explicit in SRFI 144
584 (test-deny (flnegative? zero))
585 (test-deny (flnegative? fl-least))
586 (test-deny (flnegative? posinf))
587
588 (test-deny (flodd? zero))
589 (test-assert (flodd? one))
590
591 (test-assert (fleven? zero))
592 (test-deny (fleven? one))
593
594 (test (map flfinite? somereals)
595 (map (lambda (x) #t) somereals))
596 (test (map flfinite? weird)
597 (map (lambda (x) #f) weird))
598
599 (test-assert (flinfinite? neginf))
600 (test-assert (flinfinite? posinf))
601 (test-deny (flinfinite? nan))
602 (test (map flinfinite? somereals)
603 (map (lambda (x) #f) somereals))
604
605 (test-deny (flnan? neginf))
606 (test-deny (flnan? posinf))
607 (test-assert (flnan? nan))
608 (test (map flnan? somereals)
609 (map (lambda (x) #f) somereals))
610
611 (test-assert (flnormalized? fl-greatest))
612 (test-deny (flnormalized? fl-least))
613 (test-deny (fldenormalized? fl-greatest))
614 (test-assert (fldenormalized? fl-least))
615
616 ;; Arithmetic
617
618 (test (fl+) zero)
619 (test (fl+ zero) zero)
620 (test (flzero? (fl+ negzero)) #t)
621 (test (fl+ one) one)
622 (test (fl+ one one) two)
623 (test (fl+ nan one) nan)
624 (test (fl+ one nan) nan)
625 (test (map fl+ somereals somereals somereals)
626 (map (lambda (x) (fl* (flonum 3) x))
627 somereals))
628 (test (map fl+ infinities infinities) infinities)
629 (test (map flnan?
630 (map fl+ infinities (reverse infinities)))
631 (map (lambda (x) #t) infinities))
632
633 (test (fl*) one)
634 (test (fl* zero) zero)
635 (test (flzero? (fl* negzero)) #t)
636 (test (fl* one) one)
637 (test (fl* one one) one)
638 (test (fl* nan one) nan)
639 (test (fl* one nan) nan)
640 ;; [SK] (fl* (flonum 1/3) (flonum 1/3) (flonum 1/3)) yields 1ulp error
641 ;; compared to (flonum (expt 1/3 3)).
642 (test/approx-1ulp (map fl* somereals somereals somereals)
643 (map (lambda (x) (flonum (expt x 3)))
644 somereals))
645 (test (map fl* infinities infinities)
646 (map (lambda (x) posinf) infinities))
647 (test (map fl* infinities (reverse infinities))
648 (map (lambda (x) neginf) infinities))
649
650 (let ((three (flonum 3))
651 (four (flonum 4))
652 (five (flonum 5))
653 (x23 (flonum 23))
654 (ten11 (flonum (expt 10 11)))
655 (ten12 (flonum (expt 10 12))))
656 (test (fl+* four five three) x23)
657 (cond-expand
658 [gauche.os.windows
659 ;; [SK] MinGW's fma yields 1ulp error
660 (begin
661 (test/approx-1ulp (fl+* ten11 ten12 one)
662 (flonum (+ (* (exact ten11) (exact ten12))
663 (exact one))))
664 (test/approx-1ulp (fl+* ten11 ten12 (fl- one))
665 (flonum (+ (* (exact ten11) (exact ten12))
666 (exact (fl- one))))))]
667 [else
668 (begin
669 (test (fl+* ten11 ten12 one)
670 (flonum (+ (* (exact ten11) (exact ten12)) (exact one))))
671 (test (fl+* ten11 ten12 (fl- one))
672 (flonum (+ (* (exact ten11) (exact ten12)) (exact (fl- one)))))
673 )])
674
675 ;; FIXME: the following test assumes IEEE double precision,
676 ;; in which (expt 10 23) lies exactly halfway between the
677 ;; two nearest flonums.
678 ;; [SK] MinGW's fma doesn't handle it correctly.
679 (cond-expand
680 [gauche.os.windows]
681 [else
682 (test-deny (fl=? (fl+* ten11 ten12 one)
683 (fl+* ten11 ten12 (fl- one))))]))
684
685 (test-assert (flnan? (fl+* zero posinf one)))
686 (test-assert (flnan? (fl+* zero neginf one)))
687 (test-assert (flnan? (fl+* posinf zero one)))
688 (test-assert (flnan? (fl+* neginf zero one)))
689 (test-assert (flnan? (fl+* zero posinf nan)))
690 (test-assert (flnan? (fl+* zero neginf nan)))
691 (test-assert (flnan? (fl+* posinf zero nan)))
692 (test-assert (flnan? (fl+* neginf zero nan)))
693
694 ;; POSIX spec says fma function returns either a NaN or
695 ;; an implementation-defined value in these cases.
696 (test/one-of (fl+* fl-greatest fl-greatest neginf) `(,nan ,neginf))
697 (test/one-of (fl+* fl-greatest (fl- fl-greatest) posinf) `(,nan ,posinf))
698
699 (test-assert (flnan? (fl+* nan one one)))
700 (test-assert (flnan? (fl+* one nan one)))
701 (test-assert (flnan? (fl+* one one nan)))
702
703 (test (fl- zero) negzero)
704 (test (fl- negzero) zero)
705 (test (fl- one) (flonum -1))
706 (test (fl- one one) zero)
707 (test (fl- nan one) nan)
708 (test (fl- one nan) nan)
709 (test (map fl- somereals somereals somereals)
710 (map (lambda (x) (if (eqv? x zero) zero (fl- x)))
711 somereals))
712 (test (map flnan? (map fl- infinities infinities))
713 '(#t #t))
714 (test (map fl- infinities (reverse infinities))
715 infinities)
716
717 (test (fl/ zero) posinf)
718 (test (fl/ negzero) neginf)
719 (test (fl/ one) one)
720 (test (fl/ one one) one)
721 (test (fl/ nan one) nan)
722 (test (fl/ one nan) nan)
723 (test (map fl/ somereals somereals somereals)
724 (map (lambda (x) (if (flzero? x) (fl/ zero zero) (fl/ x)))
725 somereals))
726 (test (map flnan? (map fl/ infinities infinities))
727 '(#t #t))
728 (test (map flnan? (map fl/ infinities (reverse infinities)))
729 '(#t #t))
730
731 (test (flabs zero) zero)
732 (test (flabs negzero) zero)
733 (test (flabs one) one)
734 (test (flabs (flonum -5.25)) (flonum 5.25))
735
736 (test (flabsdiff zero one) one)
737 (test (flabsdiff one zero) one)
738 (test (flabsdiff one one) zero)
739 (test (flabsdiff posinf neginf) posinf)
740 (test (flabsdiff neginf posinf) posinf)
741 #|
742 (test (flposdiff zero one) zero)
743 (test (flposdiff one zero) one)
744 (test (flposdiff one one) zero)
745 (test (flposdiff posinf neginf) posinf)
746 (test (flposdiff neginf posinf) posinf)
747 |#
748 (test (flsgn posinf) one)
749 (test (flsgn neginf) (fl- one))
750 (test (flsgn zero) one)
751 (test (flsgn negzero) (fl- one))
752 (test (flsgn two) one)
753 (test (flsgn (fl- two)) (fl- one))
754
755 (test (flnumerator (flonum 2.25)) (flonum 9))
756 (test (fldenominator (flonum 2.25)) (flonum 4))
757 (test (flnumerator (flonum -2.25)) (flonum -9))
758 (test (fldenominator (flonum -2.25)) (flonum 4))
759 (test (map flnumerator ints) ints)
760 (test (map fldenominator ints)
761 (map (lambda (x) one) ints))
762 (test (map flnumerator weird) weird)
763 (test (map fldenominator infinities) (list one one))
764 (test-assert (flnan? (flnumerator nan)))
765 (test-assert (flnan? (fldenominator nan)))
766
767 (test (flfloor (flonum -3.125)) (flonum -4))
768 (test (flceiling (flonum -3.125)) (flonum -3))
769 (test (flround (flonum -3.125)) (flonum -3))
770 (test (fltruncate (flonum -3.125)) (flonum -3))
771
772 (test (flfloor (flonum -3.75)) (flonum -4))
773 (test (flceiling (flonum -3.75)) (flonum -3))
774 (test (flround (flonum -3.75)) (flonum -4))
775 (test (fltruncate (flonum -3.75)) (flonum -3))
776
777 (test (flfloor (flonum -3.5)) (flonum -4))
778 (test (flceiling (flonum -3.5)) (flonum -3))
779 (test (flround (flonum -3.5)) (flonum -4))
780 (test (fltruncate (flonum -3.5)) (flonum -3))
781
782 (test (map flfloor ints) ints)
783 (test (map flceiling ints) ints)
784 (test (map flround ints) ints)
785 (test (map fltruncate ints) ints)
786
787 (test (map flfloor posfracs) (map (lambda (x) zero) posfracs))
788 (test (map flceiling posfracs) (map (lambda (x) one) posfracs))
789 (test (map flround posfracs) (map (lambda (x) zero) posfracs))
790 (test (map fltruncate posfracs) (map (lambda (x) zero) posfracs))
791
792 (test (map flfloor weird) weird)
793 (test (map flceiling weird) weird)
794 (test (map flround weird) weird)
795 (test (map fltruncate weird) weird)
796
797 ;; Exponents and logarithms
798
799 (test (flexp negzero) one)
800 (test (flexp zero) one)
801 ;; [SK] MUSL clib yields 1ulp error
802 ;;(test (flexp one) fl-e)
803 (test/approx (flexp one) fl-e)
804 (test/approx (flexp (fl- one)) fl-1/e)
805 (test/approx (flexp two) fl-e-2)
806 (test/approx (flexp fl-pi/4) fl-e-pi/4)
807 (test (flexp posinf) posinf)
808 (test (flexp fl-greatest) posinf)
809 (test/approx (flexp fl-least) one)
810 (test/approx (flexp (fl- fl-greatest)) zero)
811 (test/approx (flexp neginf) zero)
812
813 (test (fl+ one (flexp-1 negzero)) one)
814 (test (fl+ one (flexp-1 zero)) one)
815 (test/approx (fl+ one (flexp-1 one)) fl-e)
816 (test/approx (fl+ one (flexp-1 (fl- one))) fl-1/e)
817 (test/approx (fl+ one (flexp-1 two)) fl-e-2)
818 (test/approx (fl+ one (flexp-1 fl-pi/4)) fl-e-pi/4)
819 (test (fl+ one (flexp-1 posinf)) posinf)
820 (test (fl+ one (flexp-1 fl-greatest)) posinf)
821 (test/approx (fl+ one (flexp-1 fl-least)) one)
822 (test/approx (fl+ one (flexp-1 (fl- fl-greatest))) zero)
823 (test/approx (fl+ one (flexp-1 neginf)) zero)
824
825 (test (flexp2 negzero) one)
826 (test (flexp2 zero) one)
827 (test (flexp2 one) two)
828 (test (flexp2 (fl- one)) (fl/ two))
829 (test (flexp2 two) (fl* two two))
830 (test/approx (flexp2 fl-log2-e) fl-e)
831 (test/approx (flexp2 fl-log2-e) fl-e)
832 (test (flexp2 posinf) posinf)
833 (test (flexp2 fl-greatest) posinf)
834 (test/approx (flexp2 fl-least) one)
835 (test/approx (flexp2 (fl- fl-greatest)) zero)
836 (test/approx (flexp2 neginf) zero)
837
838 (test (flsquare zero) zero)
839 (test (flsquare one) one)
840 (test (flsquare two) (fl+ two two))
841 (test/approx (flsquare fl-sqrt-2) two)
842 (test/approx (flsquare fl-sqrt-3) (flonum 3))
843 (test/approx (flsquare fl-sqrt-5) (flonum 5))
844 (test/approx (flsquare fl-sqrt-10) (flonum 10))
845 (test (flsquare (flonum -5)) (flonum 25))
846 (test (flsquare neginf) posinf)
847 (test (flsquare posinf) posinf)
848
849 (test (flsqrt zero) zero)
850 (test (flsqrt one) one)
851 (test/approx (flsqrt two) fl-sqrt-2)
852 (test/approx (flsqrt (flonum 3)) fl-sqrt-3)
853 (test/approx (flsqrt (flonum 5)) fl-sqrt-5)
854 (test/approx (flsqrt (flonum 10)) fl-sqrt-10)
855 (test/approx (flsqrt (flonum 698)) (flonum 26.419689627245813))
856 (test (flsqrt posinf) posinf)
857
858 (test (flcbrt zero) zero)
859 (test (flcbrt one) one)
860 (test/approx (flcbrt two) fl-cbrt-2)
861 (test/approx (flcbrt (flonum 3)) fl-cbrt-3)
862 (test/approx (flcbrt (flonum 698)) (flonum 8.8705757224791313))
863 (test/approx (flcbrt (flonum 11.390625)) (flonum 2.25))
864 (test/approx (flcbrt (flonum -11.390625)) (flonum -2.25))
865 (test (flcbrt posinf) posinf)
866 (test (flcbrt neginf) neginf)
867
868 (test (flhypot zero zero) zero)
869 (test (flhypot zero one) one)
870 (test/approx (flhypot two one) fl-sqrt-5)
871 (test/approx (flhypot (fl- two) one) fl-sqrt-5)
872 (test/approx (flhypot two (fl- one)) fl-sqrt-5)
873 (test/approx (flhypot (fl- two) (fl- one)) fl-sqrt-5)
874 (test/approx (flhypot (fl/ fl-greatest two) (fl/ fl-greatest two))
875 (fl/ fl-greatest fl-sqrt-2))
876 (test (flhypot zero posinf) posinf)
877 (test (flhypot neginf zero) posinf)
878
879 (test (flexpt two zero) one)
880 (test (flexpt two one) two)
881 (test (flexpt two two) (flonum 4))
882 (test/approx (flexpt two (fl/ two)) fl-sqrt-2)
883 (test/approx (flexpt (flonum 441) (flonum 10))
884 (flonum 2.7821842944695155e26))
885 (test/approx (flexpt (flonum 441) (fl/ (flonum 5)))
886 (flonum 3.37977444523542851))
887 (for-each (lambda (x)
888 (for-each (lambda (frac)
889 (test/approx (flexpt (flexpt x frac) (fl/ frac))
890 x))
891 posfracs))
892 (filter flpositive? somereals))
893
894 (test (fllog zero) neginf)
895 (test (fllog one) zero)
896 (test/approx (fllog two) fl-log-2)
897 (test/approx (fllog (flonum 3)) fl-log-3)
898 (test/approx (fllog fl-pi) fl-log-pi)
899 (test/approx (fllog (flonum 10)) fl-log-10)
900 (test (fllog posinf) posinf)
901 (for-each (lambda (x)
902 (test/approx (flexp (fllog x)) x))
903 (filter flpositive? somereals))
904
905 (test (fllog2 zero) neginf)
906 (test (fllog2 one) zero)
907 (test (fllog2 two) one)
908 (test/approx (fllog2 fl-e) fl-log2-e)
909 (test (fllog2 posinf) posinf)
910 (for-each (lambda (x)
911 (test/approx (flexpt two (fllog2 x)) x))
912 (filter flpositive? somereals))
913
914 (test (fllog10 zero) neginf)
915 (test (fllog10 one) zero)
916 (test/approx (fllog10 fl-e) fl-log10-e)
917 (test (fllog10 (flonum 10)) one)
918 (test (fllog10 posinf) posinf)
919 (for-each (lambda (x)
920 (test/approx (flexpt (flonum 10) (fllog10 x)) x))
921 (filter flpositive? somereals))
922
923 (test-assert (flpositive? (fllog1+ fl-least)))
924 (test (fllog1+ (fl- zero one)) neginf)
925 (test (fllog1+ (fl- one one)) zero)
926 (test/approx (fllog1+ (fl- two one)) fl-log-2)
927 (test/approx (fllog1+ (fl- (flonum 3) one)) fl-log-3)
928 (test/approx (fllog1+ (fl- fl-pi one)) fl-log-pi)
929 (test/approx (fllog1+ (fl- (flonum 10) one)) fl-log-10)
930 (test (fllog1+ (fl- posinf one)) posinf)
931 (for-each (lambda (x)
932 (test/approx (flexp (fllog1+ (fl- x one))) x))
933 (filter flpositive? somereals))
934
935 (test/approx ((make-fllog-base two) fl-e) fl-log2-e)
936 (test/approx ((make-fllog-base (flonum 10)) fl-e) fl-log10-e)
937 (test/approx ((make-fllog-base fl-e) two) fl-log-2)
938 (for-each (lambda (base)
939 (let ((f (make-fllog-base base)))
940 (for-each (lambda (x)
941 (test/approx (flexpt (flonum base) (f x)) x))
942 (filter flpositive? somereals))))
943 (map flonum '(3 7 19)))
944
945 ;; Trigonometric functions
946
947 (test/approx (flsin zero) zero)
948 (test/approx (flcos zero) one)
949 (test/approx (fltan zero) zero)
950 (test/approx (flsin (flonum 0.2)) 0.19866933079506121545941)
951 (test/approx (flcos (flonum 0.2)) 0.98006657784124163112420)
952 (test/approx (flsin (flonum 0.5)) 0.47942553860420300027329)
953 (test/approx (flcos (flonum 0.5)) 0.87758256189037271611628)
954 (test/approx (flsin (flonum 0.7)) 0.64421768723769105367261)
955 (test/approx (flcos (flonum 0.7)) 0.76484218728448842625586)
956 (test/approx (flsin fl-pi/4) fl-1/sqrt-2)
957 (test/approx (flcos fl-pi/4) fl-1/sqrt-2)
958 (test/approx (flsin one) 0.84147098480789651665250)
959 (test/approx (flcos one) 0.54030230586813971740094)
960 (test/approx (flsin fl-pi/2) one)
961 (test/approx (flcos fl-pi/2) zero)
962 (test/approx (flsin two) 0.90929742682568169539602)
963 (test/approx (flcos two) -0.41614683654714238699757)
964 (test/approx (flsin (flonum 3)) 0.14112000805986722210074)
965 (test/approx (flcos (flonum 3)) -0.98999249660044545727157)
966 (test/approx (flsin fl-pi) zero)
967 (test/approx (flcos fl-pi) (fl- one))
968 (test/approx (flsin fl-2pi) zero)
969 (test/approx (flcos fl-2pi) one)
970 (test/approx (flsin (flonum 35)) -0.42818266949615100440675)
971 (test/approx (flcos (flonum 35)) -0.90369220509150675984730)
972
973 (for-each (lambda (x)
974 (test/approx (flsin x) (fl- (flsin (fl- x))))
975 (test/approx (flcos x) (flcos (fl- fl-2pi x)))
976 (test/approx (fltan x) (fl/ (flsin x) (flcos x)))
977 (test/approx (flhypot (flsin x) (flcos x)) one))
978 (filter (lambda (x)
979 (and (flnormalized? x)
980 (fl<? (flabs x) (flonum 10000))))
981 (append somereals posfracs)))
982
983 (for-each (lambda (x)
984 (test/approx (flsin (flasin x)) x)
985 (test/approx (flcos (flacos x)) x))
986 (filter (lambda (x) (fl<=? (fl- one) x one))
987 (append somereals posfracs)))
988
989
990 (let ((xs (filter (lambda (x)
991 (and (flnormalized? x)
992 (fl<? (flabs x) (flonum 10000))))
993 (append somereals posfracs))))
994 (for-each (lambda (x)
995 (let ((theta (flatan x)))
996 (test/approx (fl/ (flsin theta) (flcos theta)) x))
997 (for-each (lambda (y)
998 (let ((theta (flatan x)))
999 (test/approx (flatan (flsin theta)
1000 (flcos theta))
1001 theta)))
1002 xs))
1003 xs))
1004
1005 (test/approx (flsinh zero) zero)
1006 (test/approx (flcosh zero) one)
1007 (test/approx (flsinh (flonum 0.2)) 0.201336002541094)
1008 (test/approx (flcosh (flonum 0.2)) 1.020066755619076)
1009 (test/approx (flsinh (flonum 0.5)) 0.521095305493747)
1010 (test/approx (flcosh (flonum 0.5)) 1.127625965206381)
1011 (test/approx (flsinh (flonum 0.7)) 0.758583701839534)
1012 (test/approx (flcosh (flonum 0.7)) 1.255169005630943)
1013 (test/approx (flsinh one) 1.175201193643801)
1014 (test/approx (flcosh one) 1.543080634815244)
1015 (test/approx (flsinh two) 3.626860407847019)
1016 (test/approx (flcosh two) 3.762195691083631)
1017 (test/approx (flsinh (flonum 3)) 10.01787492740990)
1018 (test/approx (flcosh (flonum 3)) 10.06766199577777)
1019 (test/approx (flsinh (flonum 10)) 11013.23287470339)
1020 (test/approx (flcosh (flonum 10)) 11013.23292010332)
1021
1022 (for-each (lambda (x)
1023 (test/approx (flasinh (flsinh x)) x)
1024 (test/approx (flacosh (flcosh x)) (flabs x))
1025 (test/approx (flatanh (fltanh x)) x))
1026 (filter (lambda (x)
1027 (fl<? (flabs x) (flonum 100)))
1028 (append somereals posfracs (map fl- posfracs))))
1029
1030 ;; Integer division
1031
1032 (test (flquotient (flonum 9.75) (flonum 0.5)) (flonum 19))
1033 (test (flremainder (flonum 9.75) (flonum 0.5)) (flonum 0.25))
1034 (test (flquotient (flonum -9.75) (flonum 0.5)) (flonum -19))
1035 (test (flremainder (flonum -9.75) (flonum 0.5)) (flonum -0.25))
1036 (test (flquotient (flonum 9.75) (flonum -0.5)) (flonum -19))
1037 (test (flremainder (flonum 9.75) (flonum -0.5)) (flonum 0.25))
1038 (test (flquotient (flonum -9.75) (flonum -0.5)) (flonum 19))
1039 (test (flremainder (flonum -9.75) (flonum -0.5)) (flonum -0.25))
1040
1041 (let ((f (lambda (x y)
1042 (call-with-values
1043 (lambda () (flremquo x y))
1044 (lambda (r q)
1045 (list r (modulo q 8)))))))
1046
1047 (test (f (flonum 15.875) (flonum 0.5))
1048 (list (flonum -0.125) 0))
1049 (test (f (flonum 16.000) (flonum 0.5))
1050 (list (flonum +0.000) 0))
1051 (test (f (flonum 16.125) (flonum 0.5))
1052 (list (flonum +0.125) 0))
1053 (test (f (flonum 16.250) (flonum 0.5))
1054 (list (flonum +0.250) 0))
1055
1056 (test (f (flonum 16.875) (flonum 0.5))
1057 (list (flonum -0.125) 2))
1058 (test (f (flonum 17.000) (flonum 0.5))
1059 (list (flonum +0.000) 2))
1060 (test (f (flonum 17.125) (flonum 0.5))
1061 (list (flonum +0.125) 2))
1062 (test (f (flonum 17.250) (flonum 0.5))
1063 (list (flonum +0.250) 2))
1064
1065 (test (f (flonum 17.875) (flonum 0.5))
1066 (list (flonum -0.125) 4))
1067 (test (f (flonum 18.000) (flonum 0.5))
1068 (list (flonum +0.000) 4))
1069 (test (f (flonum 18.125) (flonum 0.5))
1070 (list (flonum +0.125) 4))
1071 (test (f (flonum 18.250) (flonum 0.5))
1072 (list (flonum +0.250) 4))
1073
1074 (test (f (flonum 18.875) (flonum 0.5))
1075 (list (flonum -0.125) 6))
1076 (test (f (flonum 19.000) (flonum 0.5))
1077 (list (flonum +0.000) 6))
1078 (test (f (flonum 19.125) (flonum 0.5))
1079 (list (flonum +0.125) 6))
1080 (test (f (flonum 19.250) (flonum 0.5))
1081 (list (flonum +0.250) 6))
1082
1083 (test (f (flonum 15.375) (flonum 0.5))
1084 (list (flonum -0.125) 7))
1085 (test (f (flonum 16.500) (flonum 0.5))
1086 (list (flonum +0.000) 1))
1087 (test (f (flonum 16.625) (flonum 0.5))
1088 (list (flonum +0.125) 1))
1089 (test (f (flonum 16.750) (flonum 0.5))
1090 (list (flonum -0.250) 2))
1091
1092 (test (f (flonum 16.375) (flonum 0.5))
1093 (list (flonum -0.125) 1))
1094 (test (f (flonum 17.500) (flonum 0.5))
1095 (list (flonum +0.000) 3))
1096 (test (f (flonum 17.625) (flonum 0.5))
1097 (list (flonum +0.125) 3))
1098 (test (f (flonum 17.750) (flonum 0.5))
1099 (list (flonum -0.250) 4))
1100
1101 (test (f (flonum 17.375) (flonum 0.5))
1102 (list (flonum -0.125) 3))
1103 (test (f (flonum 18.500) (flonum 0.5))
1104 (list (flonum +0.000) 5))
1105 (test (f (flonum 18.625) (flonum 0.5))
1106 (list (flonum +0.125) 5))
1107 (test (f (flonum 38.750) (flonum 0.5))
1108 (list (flonum -0.250) 6))
1109
1110 (test (f (flonum 18.375) (flonum 0.5))
1111 (list (flonum -0.125) 5))
1112 (test (f (flonum 19.500) (flonum 0.5))
1113 (list (flonum +0.000) 7))
1114 (test (f (flonum 19.625) (flonum 0.5))
1115 (list (flonum +0.125) 7))
1116 (test (f (flonum 19.750) (flonum 0.5))
1117 (list (flonum -0.250) 0))
1118
1119 )
1120
1121 ;; Special functions
1122
1123 (test/approx (flgamma (flonum 0.5)) fl-gamma-1/2)
1124 (test/approx (flgamma (flonum #i1/3)) fl-gamma-1/3)
1125 (test/approx (flgamma (flonum #i2/3)) fl-gamma-2/3)
1126 (test/approx (flgamma (flonum 0.75)) (flonum 1.225416702465178))
1127 (test (flgamma one) one)
1128 (test/approx (flgamma (flonum 1.25)) (flonum 0.906402477055477))
1129 (test/approx (flgamma (flonum 1.38)) (flonum 0.888537149431357))
1130 (test/approx (flgamma (flonum 1.50)) (fl/ (flsqrt fl-pi) two))
1131 (test (flgamma two) one)
1132 (test/approx (flgamma (flonum 11)) (flonum 3628800))
1133 (test/approx (flgamma (flonum 11.5))
1134 (* 10.5 9.5 8.5 7.5 6.5 5.5 4.5 3.5 2.5 1.5 0.5
1135 fl-gamma-1/2))
1136 (test/approx (flgamma (flonum 1.3))
1137 (* 0.3 -0.7 -1.7 -2.7 -3.7 -4.7 -5.7 -6.7
1138 (flgamma (flonum -6.7))))
1139 (test/approx (flgamma (flonum 1.3))
1140 (* 0.3 -0.7 -1.7 -2.7 -3.7 -4.7 -5.7 -6.7 -7.7
1141 (flgamma (flonum -7.7))))
1142 (test/approx (flgamma (flonum 76.5))
1143 (flonum 2.159256448318447e110))
1144 (test/approx (flgamma (flonum 100))
1145 (flonum 9.332621544439442e155))
1146
1147 (let* ((f (lambda (x)
1148 (call-with-values
1149 (lambda () (flloggamma x))
1150 list)))
1151 (g (lambda (x) (car (f x))))
1152 (s (lambda (x) (cadr (f x)))))
1153 (test/approx (g (flonum 0.5)) (log fl-gamma-1/2))
1154 (test/approx (g (flonum #i1/3)) (log fl-gamma-1/3))
1155 (test/approx (g (flonum #i2/3)) (log fl-gamma-2/3))
1156 (test/approx (g (flonum 0.75)) (log (flonum 1.225416702465178)))
1157 (test/approx (g one) (log one))
1158 (test/approx (g (flonum 1.25)) (log (flonum 0.906402477055477)))
1159 (test/approx (g (flonum 1.38)) (log (flonum 0.888537149431357)))
1160 (test/approx (g (flonum 1.50)) (log (fl/ (flsqrt fl-pi) two)))
1161 (test/approx (g two) (log one))
1162 (test/approx (g (flonum 11)) (log (flonum 3628800)))
1163 (test/approx (g (flonum 1000))
1164 (apply + (map log (cdr (iota 1000)))))
1165 (test/approx (g (flonum -0.5))
1166 (log (flabs (flgamma (flonum -0.5)))))
1167 (test/approx (g (flonum -49.2))
1168 (log (flabs (flgamma (flonum -49.2)))))
1169 (test/approx (g (flonum -50.3))
1170 (log (flabs (flgamma (flonum -50.3)))))
1171 (test/approx (g (flonum -100.5))
1172 (log (flabs (flgamma (flonum -100.5)))))
1173 (test/approx (g posinf) posinf)
1174 ;; (test/unspec-or-exn (g neginf) &error)
1175 ;; (test/unspec-or-exn (g zero) &error)
1176 ;; (test/unspec-or-exn (g nan) &error)
1177 (test (g neginf) +inf.0)
1178 (test (g zero) +inf.0)
1179 (test (g nan) +nan.0)
1180
1181 (test (s (flonum 0.5)) one)
1182 (test (s (flonum #i1/3)) one)
1183 (test (s (flonum #i2/3)) one)
1184 (test (s (flonum 0.75)) one)
1185 (test (s one) one)
1186 (test (s (flonum 1.25)) one)
1187 (test (s (flonum 1.38)) one)
1188 (test (s (flonum 1.50)) one)
1189 (test (s two) one)
1190 (test (s (flonum 11)) one)
1191 (test (s (flonum 1000)) one)
1192 (test (s (flonum -0.5)) (fl- one))
1193 (test (s (flonum -49.2)) one)
1194 (test (s (flonum -50.3)) (fl- one))
1195 (test (s (flonum -999.5)) one)
1196 (test (s (flonum -1000.5)) (fl- one))
1197 )
1198
1199 (test (flfirst-bessel 0 zero) one)
1200 (test (flfirst-bessel 1 zero) zero)
1201 (test (flfirst-bessel 2 zero) zero)
1202 (test (flfirst-bessel 3 zero) zero)
1203 (test (flfirst-bessel 4 zero) zero)
1204 (test (flfirst-bessel 5 zero) zero)
1205 (test (flfirst-bessel 6 zero) zero)
1206 (test (flfirst-bessel 7 zero) zero)
1207 (test (flfirst-bessel 8 zero) zero)
1208 (test (flfirst-bessel 9 zero) zero)
1209
1210 (test/approx (flfirst-bessel 0 (flonum 0.4))
1211 (flonum 0.960398226659563))
1212 (test/approx (flfirst-bessel 1 (flonum 0.4))
1213 (flonum 0.196026577955319))
1214 (test/approx (flfirst-bessel 2 (flonum 0.4))
1215 (flonum 0.01973466311703027))
1216 (test/approx (flfirst-bessel 3 (flonum 0.4))
1217 (flonum 1.320053214983958e-3))
1218 (test/approx (flfirst-bessel 4 (flonum 0.4))
1219 (flonum 6.613510772909677e-5))
1220 (test/approx (flfirst-bessel 5 (flonum 0.4))
1221 (flonum 2.648939597977585e-6))
1222 (test/approx (flfirst-bessel 6 (flonum 0.4))
1223 (flonum 8.838222034285578e-8))
1224 (test/approx (flfirst-bessel 7 (flonum 0.4))
1225 (flonum 2.527012308088268e-9))
1226 (test/approx (flfirst-bessel 8 (flonum 0.4))
1227 (flonum 6.321044023358773e-11))
1228 (test/approx (flfirst-bessel 9 (flonum 0.4))
1229 (flonum 1.405301255241872e-12))
1230
1231 (test/approx (flfirst-bessel 0 one)
1232 (flonum 0.765197686557967))
1233 (test/approx (flfirst-bessel 1 one)
1234 (flonum 0.440050585744934))
1235 (test/approx (flfirst-bessel 2 one)
1236 (flonum 0.114903484931900))
1237 (test/approx (flfirst-bessel 3 one)
1238 (flonum 1.956335398266841e-2))
1239 (test/approx (flfirst-bessel 4 one)
1240 (flonum 2.476638964109955e-3))
1241 (test/approx (flfirst-bessel 5 one)
1242 (flonum 2.497577302112344e-4))
1243 (test/approx (flfirst-bessel 6 one)
1244 (flonum 2.093833800238927e-5))
1245 (test/approx (flfirst-bessel 7 one)
1246 (flonum 1.502325817436808e-6))
1247 (test/approx (flfirst-bessel 8 one)
1248 (flonum 9.422344172604501e-8))
1249 (test/approx (flfirst-bessel 9 one)
1250 (flonum 5.249250179911875e-9))
1251
1252 (test/approx (flfirst-bessel 0 (flonum 17))
1253 (flonum -0.1698542521511835))
1254 (test/approx (flfirst-bessel 1 (flonum 17))
1255 (flonum -0.09766849275778065))
1256 (test/approx (flfirst-bessel 2 (flonum 17))
1257 (flonum 0.1583638412385035))
1258 (test/approx (flfirst-bessel 3 (flonum 17))
1259 (flonum 0.1349305730591932))
1260 (test/approx (flfirst-bessel 4 (flonum 17))
1261 (flonum -0.1107412860446706))
1262 (test/approx (flfirst-bessel 5 (flonum 17))
1263 (flonum -0.1870441194231559))
1264 (test/approx (flfirst-bessel 6 (flonum 17))
1265 (flonum 0.0007153334428141831))
1266 (test/approx (flfirst-bessel 7 (flonum 17))
1267 (flonum 0.1875490606769070))
1268 (test/approx (flfirst-bessel 8 (flonum 17))
1269 (flonum 0.1537368341734622))
1270 (test/approx (flfirst-bessel 9 (flonum 17))
1271 (flonum -0.04285556969011908))
1272
1273 (test/approx (flfirst-bessel 0 (flonum 50))
1274 (flonum +5.581232766925182e-2))
1275 (test/approx (flfirst-bessel 1 (flonum 50))
1276 (flonum -9.751182812517514e-2))
1277 (test/approx (flfirst-bessel 2 (flonum 50))
1278 (flonum -5.971280079425882e-2))
1279 (test/approx (flfirst-bessel 3 (flonum 50))
1280 (flonum +9.273480406163443e-2))
1281 (test/approx (flfirst-bessel 4 (flonum 50))
1282 (flonum +7.084097728165495e-2))
1283 (test/approx (flfirst-bessel 5 (flonum 50))
1284 (flonum -8.140024769656964e-2))
1285 (test/approx (flfirst-bessel 6 (flonum 50))
1286 (flonum -8.712102682096888e-2))
1287 (test/approx (flfirst-bessel 7 (flonum 50))
1288 (flonum +6.049120125953711e-2))
1289 (test/approx (flfirst-bessel 8 (flonum 50))
1290 (flonum +1.040585631736393e-1))
1291 (test/approx (flfirst-bessel 9 (flonum 50))
1292 (flonum -2.719246104397254e-2))
1293
1294 (let ((f (lambda (n x y)
1295 (test/approx (fl/ (flfirst-bessel n x) y)
1296 (flexpt x (flonum n))))))
1297 (f 10 (flonum 8) 5.659370382712330e-11)
1298 (f 11 (flonum 8) 2.979844833403859e-12)
1299 (f 20 (flonum 8) 1.804618055659560e-25)
1300 (f 21 (flonum 8) 4.456237531615702e-27))
1301
1302 (test/approx (flfirst-bessel 10 (flonum 10)) 2.074861066333589e-1)
1303 (test/approx (flfirst-bessel 15 (flonum 10)) 4.507973143721253e-3)
1304 (test/approx (flfirst-bessel 20 (flonum 10)) 1.151336924781340e-5)
1305 (test/approx (flfirst-bessel 50 (flonum 10)) 1.784513607871595e-30)
1306 (test/approx (flfirst-bessel 100 (flonum 10)) 6.597316064155381e-89)
1307
1308 (test/approx (flfirst-bessel 10 (flonum 100)) -5.473217693547201e-2)
1309 (test/approx (flfirst-bessel 15 (flonum 100)) +1.519812122392732e-2)
1310 (test/approx (flfirst-bessel 20 (flonum 100)) +6.221745849833875e-2)
1311 (test/approx (flfirst-bessel 50 (flonum 100)) -3.869833972852538e-2)
1312 (test/approx (flfirst-bessel 100 (flonum 100)) +9.636667329586156e-2)
1313
1314
1315 (test (flsecond-bessel 0 zero) neginf)
1316 (test (flsecond-bessel 1 zero) neginf)
1317 (test (flsecond-bessel 2 zero) neginf)
1318 (test (flsecond-bessel 3 zero) neginf)
1319 (test (flsecond-bessel 4 zero) neginf)
1320 (test (flsecond-bessel 5 zero) neginf)
1321 (test (flsecond-bessel 6 zero) neginf)
1322 (test (flsecond-bessel 7 zero) neginf)
1323 (test (flsecond-bessel 8 zero) neginf)
1324 (test (flsecond-bessel 9 zero) neginf)
1325 (test (flsecond-bessel 10 zero) neginf)
1326 (test (flsecond-bessel 20 zero) neginf)
1327
1328 (test/approx (flsecond-bessel 0 (flonum 0.4))
1329 (flonum -0.6060245684270096))
1330 (test/approx (flsecond-bessel 1 (flonum 0.4))
1331 (flonum -1.780872044270051))
1332 (test/approx (flsecond-bessel 2 (flonum 0.4))
1333 (flonum -8.298335652923247))
1334 (test/approx (flsecond-bessel 3 (flonum 0.4))
1335 (flonum -8.120248448496242e1))
1336 (test/approx (flsecond-bessel 4 (flonum 0.4))
1337 (flonum -1.209738931621513e3))
1338 (test/approx (flsecond-bessel 5 (flonum 0.4))
1339 (flonum -2.411357614794530e4))
1340 (test/approx (flsecond-bessel 6 (flonum 0.4))
1341 (flonum -6.016296647670110e5))
1342 (test/approx (flsecond-bessel 7 (flonum 0.4))
1343 (flonum -1.802477636686238e7))
1344 (test/approx (flsecond-bessel 8 (flonum 0.4))
1345 (flonum -6.302655431754164e8))
1346 (test/approx (flsecond-bessel 9 (flonum 0.4))
1347 (flonum -2.519259695064979e10))
1348
1349 (test/approx (flsecond-bessel 0 one)
1350 (flonum +0.08825696421567696))
1351 (test/approx (flsecond-bessel 1 one)
1352 (flonum -0.7812128213002887))
1353 (test/approx (flsecond-bessel 2 one)
1354 (flonum -1.650682606816254))
1355 (test/approx (flsecond-bessel 3 one)
1356 (flonum -5.821517605964729))
1357 (test/approx (flsecond-bessel 4 one)
1358 (flonum -3.327842302897212e1))
1359 (test/approx (flsecond-bessel 5 one)
1360 (flonum -2.604058666258122e2))
1361 (test/approx (flsecond-bessel 6 one)
1362 (flonum -2.570780243229150e3))
1363 (test/approx (flsecond-bessel 7 one)
1364 (flonum -3.058895705212399e4))
1365 (test/approx (flsecond-bessel 8 one)
1366 (flonum -4.256746184865067e5))
1367 (test/approx (flsecond-bessel 9 one)
1368 (flonum -6.780204938731983e6))
1369
1370 (test/approx (flsecond-bessel 0 (flonum 17))
1371 (flonum -0.09263719844232369))
1372 (test/approx (flsecond-bessel 1 (flonum 17))
1373 (flonum +0.1672050360772337))
1374 (test/approx (flsecond-bessel 2 (flonum 17))
1375 (flonum +0.1123083791572924))
1376 (test/approx (flsecond-bessel 3 (flonum 17))
1377 (flonum -0.1407795350990472))
1378 (test/approx (flsecond-bessel 4 (flonum 17))
1379 (flonum -0.1619952738981326))
1380 (test/approx (flsecond-bessel 5 (flonum 17))
1381 (flonum +0.06454646502933781))
1382 (test/approx (flsecond-bessel 6 (flonum 17))
1383 (flonum +0.1999637827389195))
1384 (test/approx (flsecond-bessel 7 (flonum 17))
1385 (flonum +0.07660444043342891))
1386 (test/approx (flsecond-bessel 8 (flonum 17))
1387 (flonum -0.1368777729702134))
1388 (test/approx (flsecond-bessel 9 (flonum 17))
1389 (flonum -0.2054305796995121))
1390
1391 (test/approx (flsecond-bessel 0 (flonum 50))
1392 (flonum -9.806499547007708e-2))
1393 (test/approx (flsecond-bessel 1 (flonum 50))
1394 (flonum -5.679566856201477e-2))
1395 (test/approx (flsecond-bessel 2 (flonum 50))
1396 (flonum +9.579316872759649e-2))
1397 (test/approx (flsecond-bessel 3 (flonum 50))
1398 (flonum +6.445912206022249e-2))
1399 (test/approx (flsecond-bessel 4 (flonum 50))
1400 (flonum -8.805807408036979e-2))
1401 (test/approx (flsecond-bessel 5 (flonum 50))
1402 (flonum -7.854841391308165e-2))
1403 (test/approx (flsecond-bessel 6 (flonum 50))
1404 (flonum +7.234839129775346e-2))
1405 (test/approx (flsecond-bessel 7 (flonum 50))
1406 (flonum +9.591202782454248e-2))
1407 (test/approx (flsecond-bessel 8 (flonum 50))
1408 (flonum -4.549302350688156e-2))
1409 (test/approx (flsecond-bessel 9 (flonum 50))
1410 (flonum -1.104697953467446e-1))
1411
1412 (let ((f (lambda (n x y)
1413 (test/approx (fl/ (flsecond-bessel n x) y)
1414 (flexpt x (flonum (- n)))))))
1415 (f 10 (flonum 8) -0.97356279e9)
1416 (f 20 (flonum 8) -0.962608e23)
1417 )
1418
1419 (test/approx (flsecond-bessel 10 (flonum 10)) -3.598141521834027e-1)
1420 (test/approx (flsecond-bessel 15 (flonum 10)) -6.364745876939129e0)
1421 (test/approx (flsecond-bessel 20 (flonum 10)) -1.597483848269626e3)
1422 (test/approx (flsecond-bessel 50 (flonum 10)) -3.641066501800740e27)
1423 (test/approx (flsecond-bessel 100 (flonum 10)) -4.849148271180607e85)
1424
1425 (test/approx (flsecond-bessel 10 (flonum 100)) +5.833157423641493e-2)
1426 (test/approx (flsecond-bessel 15 (flonum 100)) +7.879068694670284e-2)
1427 (test/approx (flsecond-bessel 20 (flonum 100)) +5.124797307618842e-2)
1428 (test/approx (flsecond-bessel 50 (flonum 100)) +7.650526394480304e-2)
1429 (test/approx (flsecond-bessel 100 (flonum 100)) -1.669214114175765e-1)
1430
1431
1432 (test (flerf zero) zero)
1433 (test (flerf posinf) one)
1434 (test (flerf neginf) (fl- one))
1435
1436 (test/approx (flerf (flonum -0.5)) -0.5204998778130465)
1437 (test/approx (flerf (flonum -1.0)) -0.8427007929497149)
1438 (test/approx (flerf (flonum -1.5)) -0.9661051464753107)
1439 (test/approx (flerf (flonum -2.0)) -0.9953222650189527)
1440
1441 (test/approx (flerf (flonum 0.25)) 0.2763263901682369)
1442 (test/approx (flerf (flonum 0.50)) 0.5204998778130465)
1443 (test/approx (flerf (flonum 0.75)) 0.7111556336535151)
1444 (test/approx (flerf (flonum 1.00)) 0.8427007929497149)
1445 (test/approx (flerf (flonum 1.25)) 0.9229001282564582)
1446 (test/approx (flerf (flonum 1.50)) 0.9661051464753107)
1447 (test/approx (flerf (flonum 1.75)) 0.9866716712191824)
1448 (test/approx (flerf (flonum 2.00)) 0.9953222650189527)
1449
1450 (test (flerfc zero) one)
1451 (test (flerfc posinf) zero)
1452 (test (flerfc neginf) two)
1453
1454 (test/approx (flerfc (flonum -0.5)) 1.520499877813047)
1455 (test/approx (flerfc (flonum -1.0)) 1.842700792949715)
1456 (test/approx (flerfc (flonum -1.5)) 1.966105146475310)
1457 (test/approx (flerfc (flonum -2.0)) 1.995322265018953)
1458
1459 (test/approx (flerfc (flonum 0.25)) (- 1.0 0.2763263901682369))
1460 (test/approx (flerfc (flonum 0.50)) (- 1.0 0.5204998778130465))
1461 (test/approx (flerfc (flonum 0.75)) (- 1.0 0.7111556336535151))
1462 (test/approx (flerfc (flonum 1.00)) (- 1.0 0.8427007929497149))
1463 (test/approx (flerfc (flonum 1.25)) (- 1.0 0.9229001282564582))
1464 (test/approx (flerfc (flonum 1.50)) (- 1.0 0.9661051464753107))
1465 (test/approx (flerfc (flonum 1.75)) (- 1.0 0.9866716712191824))
1466 (test/approx (flerfc (flonum 2.00)) (- 1.0 0.9953222650189527))
1467
1468 (let* ((f (lambda (x y)
1469 (test/approx (fl* x (flexp (flsquare x)) (flerfc x))
1470 y)))
1471 (g (lambda (x^-2 y)
1472 (f (flsqrt (fl/ x^-2)) y))))
1473 (g (flonum 0.250) 0.5107913526210115)
1474 (g (flonum 0.125) 0.5340672374463438)
1475 (g (flonum 0.100) 0.5394141079847177)
1476 (g (flonum 0.075) 0.5450551142044333)
1477 (g (flonum 0.050) 0.5510294916242269)
1478 (g (flonum 0.025) 0.5573864515094235)
1479 (g (flonum 0.020) 0.5587090260270524)
1480 (g (flonum 0.015) 0.5600499741400112)
1481 (g (flonum 0.010) 0.5614099274382259)
1482 (g (flonum 0.005) 0.5627895581750243))
1483
1484 )))