|
1
|
+;;; Tests for NaN comparisons.
|
|
2
|
+(defpackage :nan-tests
|
|
3
|
+ (:use :cl :lisp-unit))
|
|
4
|
+
|
|
5
|
+(in-package :nan-tests)
|
|
6
|
+
|
|
7
|
+(defparameter *single-float-nan*
|
|
8
|
+ (ext:with-float-traps-masked (:invalid :divide-by-zero)
|
|
9
|
+ (/ 0d0 0d0)))
|
|
10
|
+
|
|
11
|
+(defparameter *double-float-nan*
|
|
12
|
+ (ext:with-float-traps-masked (:invalid :divide-by-zero)
|
|
13
|
+ (/ 0d0 0d0)))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+(eval-when (:compile-toplevel :load-toplevel :execute)
|
|
17
|
+ (macrolet
|
|
18
|
+ ((frob (ntype op)
|
|
19
|
+ (let* ((name (ext:symbolicate (if (eq ntype 'single-float)
|
|
20
|
+ "S"
|
|
21
|
+ "D")
|
|
22
|
+ "TST-" op))
|
|
23
|
+ (name3 (ext:symbolicate name "3")))
|
|
24
|
+
|
|
25
|
+ `(progn
|
|
26
|
+ (defun ,name (x y)
|
|
27
|
+ (declare (,ntype x y))
|
|
28
|
+ (,op x y))
|
|
29
|
+ (defun ,name3 (x y z)
|
|
30
|
+ (declare (,ntype x y z))
|
|
31
|
+ (,op x y z))))))
|
|
32
|
+ (frob single-float <)
|
|
33
|
+ (frob single-float >)
|
|
34
|
+ (frob double-float <)
|
|
35
|
+ (frob double-float >)))
|
|
36
|
+
|
|
37
|
+(define-test nan-single.<
|
|
38
|
+ (:tag :nan)
|
|
39
|
+ ;; First just make sure it works with regular single-floats
|
|
40
|
+ (assert-true (stst-< 1f0 2f0))
|
|
41
|
+ (assert-false (stst-< 1f0 1f0))
|
|
42
|
+ (assert-false (stst-< 1f0 0f0))
|
|
43
|
+ ;; Now try NaN. All comparisons should be false.
|
|
44
|
+ (ext:with-float-traps-masked (:invalid)
|
|
45
|
+ (assert-false (stst-< *single-float-nan* 1f0))
|
|
46
|
+ (assert-false (stst-< 1f0 *single-float-nan*))
|
|
47
|
+ (assert-false (stst-< *single-float-nan* *single-float-nan*))))
|
|
48
|
+
|
|
49
|
+(define-test nan-double.<
|
|
50
|
+ (:tag :nan)
|
|
51
|
+ ;; First just make sure it works with regular single-floats
|
|
52
|
+ (assert-true (dtst-< 1d0 2d0))
|
|
53
|
+ (assert-false (dtst-< 1d0 1d0))
|
|
54
|
+ (assert-false (dtst-< 1d0 0d0))
|
|
55
|
+ ;; Now try NaN. All comparisons should be false.
|
|
56
|
+ (ext:with-float-traps-masked (:invalid)
|
|
57
|
+ (assert-false (dtst-< *double-float-nan* 1d0))
|
|
58
|
+ (assert-false (dtst-< 1d0 *double-float-nan*))
|
|
59
|
+ (assert-false (dtst-< *double-float-nan* *double-float-nan*))))
|
|
60
|
+
|
|
61
|
+(define-test nan-single.>
|
|
62
|
+ (:tag :nan)
|
|
63
|
+ ;; First just make sure it works with regular single-floats
|
|
64
|
+ (assert-true (stst-> 2f0 1f0))
|
|
65
|
+ (assert-false (stst-> 1f0 1f0))
|
|
66
|
+ (assert-false (stst-> 0f0 1f0))
|
|
67
|
+ ;; Now try NaN. All comparisons should be false.
|
|
68
|
+ (ext:with-float-traps-masked (:invalid)
|
|
69
|
+ (assert-false (stst-> *single-float-nan* 1f0))
|
|
70
|
+ (assert-false (stst-> 1f0 *single-float-nan*))
|
|
71
|
+ (assert-false (stst-> *single-float-nan* *single-float-nan*))))
|
|
72
|
+
|
|
73
|
+(define-test nan-double.>
|
|
74
|
+ (:tag :nan)
|
|
75
|
+ ;; First just make sure it works with regular single-floats
|
|
76
|
+ (assert-true (dtst-> 2d0 1d0))
|
|
77
|
+ (assert-false (dtst-> 1d0 1d0))
|
|
78
|
+ (assert-false (dtst-> 0d0 1d0))
|
|
79
|
+ ;; Now try NaN. All comparisons should be false.
|
|
80
|
+ (ext:with-float-traps-masked (:invalid)
|
|
81
|
+ (assert-false (dtst-> *double-float-nan* 1d0))
|
|
82
|
+ (assert-false (dtst-> 1d0 *double-float-nan*))
|
|
83
|
+ (assert-false (dtst-> *double-float-nan* *double-float-nan*))))
|
|
84
|
+
|
|
85
|
+(define-test nan-single.<3
|
|
86
|
+ (:tag :nan)
|
|
87
|
+ ;; First just make sure it works with regular single-floats
|
|
88
|
+ (assert-true (stst-<3 1f0 2f0 3f0))
|
|
89
|
+ (assert-false (stst-<3 1f0 2f0 2f0))
|
|
90
|
+ (assert-false (stst-<3 1f0 1f0 2f0))
|
|
91
|
+ (assert-false (stst-<3 1f0 0f0 2f0))
|
|
92
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
93
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
94
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
95
|
+ ;; args into paris of comparisons.
|
|
96
|
+ ;;
|
|
97
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
98
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
99
|
+ (ext:with-float-traps-masked (:invalid)
|
|
100
|
+ (assert-false (stst-<3 *single-float-nan* 2f0 3f0))
|
|
101
|
+ (assert-false (stst-<3 1f0 *single-float-nan* 3f0))
|
|
102
|
+ (assert-false (stst-<3 *single-float-nan* *single-float-nan* 3f0))))
|
|
103
|
+
|
|
104
|
+(define-test nan-double.<3
|
|
105
|
+ (:tag :nan)
|
|
106
|
+ ;; First just make sure it works with regular double-floats
|
|
107
|
+ (assert-true (dtst-<3 1d0 2d0 3d0))
|
|
108
|
+ (assert-false (dtst-<3 1d0 2d0 2d0))
|
|
109
|
+ (assert-false (dtst-<3 1d0 1d0 2d0))
|
|
110
|
+ (assert-false (dtst-<3 1d0 0d0 2d0))
|
|
111
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
112
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
113
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
114
|
+ ;; args into paris of comparisons.
|
|
115
|
+ ;;
|
|
116
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
117
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
118
|
+ (ext:with-float-traps-masked (:invalid)
|
|
119
|
+ (assert-false (dtst-<3 *double-float-nan* 2d0 3d0))
|
|
120
|
+ (assert-false (dtst-<3 1d0 *double-float-nan* 3d0))
|
|
121
|
+ (assert-false (dtst-<3 *double-float-nan* *double-float-nan* 3d0))))
|
|
122
|
+
|
|
123
|
+(define-test nan-single.>3
|
|
124
|
+ (:tag :nan)
|
|
125
|
+ ;; First just make sure it works with regular single-floats
|
|
126
|
+ (assert-true (stst->3 3f0 2f0 1f0))
|
|
127
|
+ (assert-false (stst->3 3f0 1f0 1f0))
|
|
128
|
+ (assert-false (stst->3 2f0 2f0 1f0))
|
|
129
|
+ (assert-false (stst->3 0f0 2f0 1f0))
|
|
130
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
131
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
132
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
133
|
+ ;; args into paris of comparisons.
|
|
134
|
+ ;;
|
|
135
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
136
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
137
|
+ (ext:with-float-traps-masked (:invalid)
|
|
138
|
+ (assert-false (stst->3 *single-float-nan* 2f0 3f0))
|
|
139
|
+ (assert-false (stst->3 1f0 *single-float-nan* 3f0))
|
|
140
|
+ (assert-false (stst->3 *single-float-nan* *single-float-nan* 3f0))))
|
|
141
|
+
|
|
142
|
+(define-test nan-double.>3
|
|
143
|
+ (:tag :nan)
|
|
144
|
+ ;; First just make sure it works with regular double-floats
|
|
145
|
+ (assert-true (dtst->3 3d0 2d0 1d0))
|
|
146
|
+ (assert-false (dtst->3 3d0 1d0 1d0))
|
|
147
|
+ (assert-false (dtst->3 2d0 2d0 1d0))
|
|
148
|
+ (assert-false (dtst->3 0d0 2d0 1d0))
|
|
149
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
150
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
151
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
152
|
+ ;; args into paris of comparisons.
|
|
153
|
+ ;;
|
|
154
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
155
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
156
|
+ (ext:with-float-traps-masked (:invalid)
|
|
157
|
+ (assert-false (dtst->3 *double-float-nan* 2d0 3d0))
|
|
158
|
+ (assert-false (dtst->3 1d0 *double-float-nan* 3d0))
|
|
159
|
+ (assert-false (dtst->3 *double-float-nan* *double-float-nan* 3d0))))
|
|
160
|
+ |