| 1 |
|
| 2 |
(library (tests fldiv-and-mod) |
| 3 |
(export run-tests) |
| 4 |
(import (ikarus)) |
| 5 |
|
| 6 |
(define (run-tests) |
| 7 |
(test-fldiv-and-mod) |
| 8 |
(test-fldiv0-and-mod0)) |
| 9 |
|
| 10 |
|
| 11 |
(define (test-fldiv-and-mod) |
| 12 |
(define (test x1 x2 verify?) |
| 13 |
(let-values ([(d m) (fldiv-and-mod x1 x2)]) |
| 14 |
(printf "(fldiv-and-mod ~s ~s) = ~s ~s\n" x1 x2 d m) |
| 15 |
(when verify? |
| 16 |
(assert (= d (fldiv x1 x2))) |
| 17 |
(assert (= m (flmod x1 x2))) |
| 18 |
(assert (<= 0.0 m)) |
| 19 |
(assert (< m (abs x2))) |
| 20 |
(assert (= x1 (+ (* d x2) m)))))) |
| 21 |
(test +17.0 +3.0 #t) |
| 22 |
(test +17.0 -3.0 #t) |
| 23 |
(test -17.0 +3.0 #t) |
| 24 |
(test -17.0 -3.0 #t) |
| 25 |
(test +16.0 +3.0 #t) |
| 26 |
(test +16.0 -3.0 #t) |
| 27 |
(test -16.0 +3.0 #t) |
| 28 |
(test -16.0 -3.0 #t) |
| 29 |
(test +15.0 +3.0 #t) |
| 30 |
(test +15.0 -3.0 #t) |
| 31 |
(test -15.0 +3.0 #t) |
| 32 |
(test -15.0 -3.0 #t) |
| 33 |
(test +17.0 +3.5 #t) |
| 34 |
(test +17.0 -3.5 #t) |
| 35 |
(test -17.0 +3.5 #t) |
| 36 |
(test -17.0 -3.5 #t) |
| 37 |
(test +16.0 +3.5 #t) |
| 38 |
(test +16.0 -3.5 #t) |
| 39 |
(test -16.0 +3.5 #t) |
| 40 |
(test -16.0 -3.5 #t) |
| 41 |
(test +15.0 +3.5 #t) |
| 42 |
(test +15.0 -3.5 #t) |
| 43 |
(test -15.0 +3.5 #t) |
| 44 |
(test -15.0 -3.5 #t) |
| 45 |
(test +17.0 +nan.0 #f) |
| 46 |
(test -17.0 +nan.0 #f) |
| 47 |
(test +17.0 +inf.0 #f) |
| 48 |
(test +17.0 -inf.0 #f) |
| 49 |
(test -17.0 +inf.0 #f) |
| 50 |
(test -17.0 -inf.0 #f)) |
| 51 |
|
| 52 |
(define (test-fldiv0-and-mod0) |
| 53 |
(define (test x1 x2 verify?) |
| 54 |
(let-values ([(d m) (fldiv0-and-mod0 x1 x2)]) |
| 55 |
(printf "(fldiv0-and-mod0 ~s ~s) = ~s ~s\n" x1 x2 d m) |
| 56 |
(when verify? |
| 57 |
(assert (= d (fldiv0 x1 x2))) |
| 58 |
(assert (= m (flmod0 x1 x2))) |
| 59 |
(assert (<= (fl- (flabs (fl/ x2 2.0))) m)) |
| 60 |
(assert (< m (flabs (fl/ x2 2.0)))) |
| 61 |
(assert (= x1 (+ (* d x2) m)))))) |
| 62 |
(test +17.0 +3.0 #t) |
| 63 |
(test +17.0 -3.0 #t) |
| 64 |
(test -17.0 +3.0 #t) |
| 65 |
(test -17.0 -3.0 #t) |
| 66 |
(test +16.0 +3.0 #t) |
| 67 |
(test +16.0 -3.0 #t) |
| 68 |
(test -16.0 +3.0 #t) |
| 69 |
(test -16.0 -3.0 #t) |
| 70 |
(test +15.0 +3.0 #t) |
| 71 |
(test +15.0 -3.0 #t) |
| 72 |
(test -15.0 +3.0 #t) |
| 73 |
(test -15.0 -3.0 #t) |
| 74 |
(test +17.0 +3.5 #t) |
| 75 |
(test +17.0 -3.5 #t) |
| 76 |
(test -17.0 +3.5 #t) |
| 77 |
(test -17.0 -3.5 #t) |
| 78 |
(test +16.0 +3.5 #t) |
| 79 |
(test +16.0 -3.5 #t) |
| 80 |
(test -16.0 +3.5 #t) |
| 81 |
(test -16.0 -3.5 #t) |
| 82 |
(test +15.0 +3.5 #t) |
| 83 |
(test +15.0 -3.5 #t) |
| 84 |
(test -15.0 +3.5 #t) |
| 85 |
(test -15.0 -3.5 #t) |
| 86 |
(test +10.0 +4.0 #t) |
| 87 |
(test +10.0 -4.0 #t) |
| 88 |
(test -10.0 +4.0 #t) |
| 89 |
(test -10.0 -4.0 #t) |
| 90 |
(test +17.0 +nan.0 #f) |
| 91 |
(test -17.0 +nan.0 #f) |
| 92 |
(test +17.0 +inf.0 #f) |
| 93 |
(test +17.0 -inf.0 #f) |
| 94 |
(test -17.0 +inf.0 #f) |
| 95 |
(test -17.0 -inf.0 #f)) |
| 96 |
) |