|
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
|
+ (frob single-float =)
|
|
37
|
+ (frob double-float =)))
|
|
38
|
+
|
|
39
|
+(define-test nan-single.<
|
|
40
|
+ (:tag :nan)
|
|
41
|
+ ;; First just make sure it works with regular single-floats
|
|
42
|
+ (assert-true (stst-< 1f0 2f0))
|
|
43
|
+ (assert-false (stst-< 1f0 1f0))
|
|
44
|
+ (assert-false (stst-< 1f0 0f0))
|
|
45
|
+ ;; Now try NaN. All comparisons should be false.
|
|
46
|
+ (ext:with-float-traps-masked (:invalid)
|
|
47
|
+ (assert-false (stst-< *single-float-nan* 1f0))
|
|
48
|
+ (assert-false (stst-< 1f0 *single-float-nan*))
|
|
49
|
+ (assert-false (stst-< *single-float-nan* *single-float-nan*))))
|
|
50
|
+
|
|
51
|
+(define-test nan-double.<
|
|
52
|
+ (:tag :nan)
|
|
53
|
+ ;; First just make sure it works with regular single-floats
|
|
54
|
+ (assert-true (dtst-< 1d0 2d0))
|
|
55
|
+ (assert-false (dtst-< 1d0 1d0))
|
|
56
|
+ (assert-false (dtst-< 1d0 0d0))
|
|
57
|
+ ;; Now try NaN. All comparisons should be false.
|
|
58
|
+ (ext:with-float-traps-masked (:invalid)
|
|
59
|
+ (assert-false (dtst-< *double-float-nan* 1d0))
|
|
60
|
+ (assert-false (dtst-< 1d0 *double-float-nan*))
|
|
61
|
+ (assert-false (dtst-< *double-float-nan* *double-float-nan*))))
|
|
62
|
+
|
|
63
|
+(define-test nan-single.>
|
|
64
|
+ (:tag :nan)
|
|
65
|
+ ;; First just make sure it works with regular single-floats
|
|
66
|
+ (assert-true (stst-> 2f0 1f0))
|
|
67
|
+ (assert-false (stst-> 1f0 1f0))
|
|
68
|
+ (assert-false (stst-> 0f0 1f0))
|
|
69
|
+ ;; Now try NaN. All comparisons should be false.
|
|
70
|
+ (ext:with-float-traps-masked (:invalid)
|
|
71
|
+ (assert-false (stst-> *single-float-nan* 1f0))
|
|
72
|
+ (assert-false (stst-> 1f0 *single-float-nan*))
|
|
73
|
+ (assert-false (stst-> *single-float-nan* *single-float-nan*))))
|
|
74
|
+
|
|
75
|
+(define-test nan-double.>
|
|
76
|
+ (:tag :nan)
|
|
77
|
+ ;; First just make sure it works with regular single-floats
|
|
78
|
+ (assert-true (dtst-> 2d0 1d0))
|
|
79
|
+ (assert-false (dtst-> 1d0 1d0))
|
|
80
|
+ (assert-false (dtst-> 0d0 1d0))
|
|
81
|
+ ;; Now try NaN. All comparisons should be false.
|
|
82
|
+ (ext:with-float-traps-masked (:invalid)
|
|
83
|
+ (assert-false (dtst-> *double-float-nan* 1d0))
|
|
84
|
+ (assert-false (dtst-> 1d0 *double-float-nan*))
|
|
85
|
+ (assert-false (dtst-> *double-float-nan* *double-float-nan*))))
|
|
86
|
+
|
|
87
|
+(define-test nan-single.<3
|
|
88
|
+ (:tag :nan)
|
|
89
|
+ ;; First just make sure it works with regular single-floats
|
|
90
|
+ (assert-true (stst-<3 1f0 2f0 3f0))
|
|
91
|
+ (assert-false (stst-<3 1f0 2f0 2f0))
|
|
92
|
+ (assert-false (stst-<3 1f0 1f0 2f0))
|
|
93
|
+ (assert-false (stst-<3 1f0 0f0 2f0))
|
|
94
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
95
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
96
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
97
|
+ ;; args into paris of comparisons.
|
|
98
|
+ ;;
|
|
99
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
100
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
101
|
+ (ext:with-float-traps-masked (:invalid)
|
|
102
|
+ (assert-false (stst-<3 *single-float-nan* 2f0 3f0))
|
|
103
|
+ (assert-false (stst-<3 1f0 *single-float-nan* 3f0))
|
|
104
|
+ (assert-false (stst-<3 *single-float-nan* *single-float-nan* 3f0))))
|
|
105
|
+
|
|
106
|
+(define-test nan-double.<3
|
|
107
|
+ (:tag :nan)
|
|
108
|
+ ;; First just make sure it works with regular double-floats
|
|
109
|
+ (assert-true (dtst-<3 1d0 2d0 3d0))
|
|
110
|
+ (assert-false (dtst-<3 1d0 2d0 2d0))
|
|
111
|
+ (assert-false (dtst-<3 1d0 1d0 2d0))
|
|
112
|
+ (assert-false (dtst-<3 1d0 0d0 2d0))
|
|
113
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
114
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
115
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
116
|
+ ;; args into paris of comparisons.
|
|
117
|
+ ;;
|
|
118
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
119
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
120
|
+ (ext:with-float-traps-masked (:invalid)
|
|
121
|
+ (assert-false (dtst-<3 *double-float-nan* 2d0 3d0))
|
|
122
|
+ (assert-false (dtst-<3 1d0 *double-float-nan* 3d0))
|
|
123
|
+ (assert-false (dtst-<3 *double-float-nan* *double-float-nan* 3d0))))
|
|
124
|
+
|
|
125
|
+(define-test nan-single.>3
|
|
126
|
+ (:tag :nan)
|
|
127
|
+ ;; First just make sure it works with regular single-floats
|
|
128
|
+ (assert-true (stst->3 3f0 2f0 1f0))
|
|
129
|
+ (assert-false (stst->3 3f0 1f0 1f0))
|
|
130
|
+ (assert-false (stst->3 2f0 2f0 1f0))
|
|
131
|
+ (assert-false (stst->3 0f0 2f0 1f0))
|
|
132
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
133
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
134
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
135
|
+ ;; args into paris of comparisons.
|
|
136
|
+ ;;
|
|
137
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
138
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
139
|
+ (ext:with-float-traps-masked (:invalid)
|
|
140
|
+ (assert-false (stst->3 *single-float-nan* 2f0 3f0))
|
|
141
|
+ (assert-false (stst->3 1f0 *single-float-nan* 3f0))
|
|
142
|
+ (assert-false (stst->3 *single-float-nan* *single-float-nan* 3f0))))
|
|
143
|
+
|
|
144
|
+(define-test nan-double.>3
|
|
145
|
+ (:tag :nan)
|
|
146
|
+ ;; First just make sure it works with regular double-floats
|
|
147
|
+ (assert-true (dtst->3 3d0 2d0 1d0))
|
|
148
|
+ (assert-false (dtst->3 3d0 1d0 1d0))
|
|
149
|
+ (assert-false (dtst->3 2d0 2d0 1d0))
|
|
150
|
+ (assert-false (dtst->3 0d0 2d0 1d0))
|
|
151
|
+ ;; Now try NaN. Currently we can only test if there's NaN in the
|
|
152
|
+ ;; first two args. When NaN is the last arg, we return the
|
|
153
|
+ ;; incorrect value because of how multi-compare converts multiple
|
|
154
|
+ ;; args into paris of comparisons.
|
|
155
|
+ ;;
|
|
156
|
+ ;; When that is fixed, we can add additional tests. Nevertheless,
|
|
157
|
+ ;; this is useful because it tests the not-p case of the vops.
|
|
158
|
+ (ext:with-float-traps-masked (:invalid)
|
|
159
|
+ (assert-false (dtst->3 *double-float-nan* 2d0 3d0))
|
|
160
|
+ (assert-false (dtst->3 1d0 *double-float-nan* 3d0))
|
|
161
|
+ (assert-false (dtst->3 *double-float-nan* *double-float-nan* 3d0))))
|
|
162
|
+
|
|
163
|
+(define-test nan-single.=
|
|
164
|
+ (:tag :nan)
|
|
165
|
+ ;; Basic tests with regular numbers.
|
|
166
|
+ (assert-true (stst-= 1f0 1f0))
|
|
167
|
+ (assert-false (stst-= 2f0 1f0))
|
|
168
|
+ (assert-false (stst-= 0f0 1f0))
|
|
169
|
+ ;; Tests with NaN, where = should fail.
|
|
170
|
+ (ext:with-float-traps-masked (:invalid)
|
|
171
|
+ (assert-false (stst-= *single-float-nan* 1f0))
|
|
172
|
+ (assert-false (stst-= 1f0 *single-float-nan*))
|
|
173
|
+ (assert-false (stst-= *single-float-nan* *single-float-nan*))))
|
|
174
|
+
|
|
175
|
+(define-test nan-double.=
|
|
176
|
+ (:tag :nan)
|
|
177
|
+ ;; Basic tests with regular numbers.
|
|
178
|
+ (assert-true (stst-= 1d0 1d0))
|
|
179
|
+ (assert-false (stst-= 2d0 1d0))
|
|
180
|
+ (assert-false (stst-= 0d0 1d0))
|
|
181
|
+ ;; Tests with NaN, where = should fail.
|
|
182
|
+ (ext:with-float-traps-masked (:invalid)
|
|
183
|
+ (assert-false (stst-= *double-float-nan* 1d0))
|
|
184
|
+ (assert-false (stst-= 1d0 *double-float-nan*))
|
|
185
|
+ (assert-false (stst-= *double-float-nan* *double-float-nan*))))
|
|
186
|
+
|
|
187
|
+(define-test nan-single.=3
|
|
188
|
+ (:tag :nan)
|
|
189
|
+ ;; Basic tests with regular numbers.
|
|
190
|
+ (assert-true (stst-=3 1f0 1f0 1f0))
|
|
191
|
+ (assert-false (stst-=3 1f0 1f0 0f0))
|
|
192
|
+ (assert-false (stst-=3 0f0 1f0 1f0))
|
|
193
|
+ ;; Tests with NaN, where = should fail.
|
|
194
|
+ (ext:with-float-traps-masked (:invalid)
|
|
195
|
+ (assert-false (stst-=3 *single-float-nan* 1f0 1f0))
|
|
196
|
+ (assert-false (stst-=3 1f0 *single-float-nan* 1f0))
|
|
197
|
+ (assert-false (stst-=3 1f0 1f0 *single-float-nan*))))
|
|
198
|
+
|
|
199
|
+(define-test nan-double.=3
|
|
200
|
+ (:tag :nan)
|
|
201
|
+ ;; Basic tests with regular numbers.
|
|
202
|
+ (assert-true (dtst-=3 1d0 1d0 1d0))
|
|
203
|
+ (assert-false (dtst-=3 1d0 1d0 0d0))
|
|
204
|
+ (assert-false (dtst-=3 0d0 1d0 1d0))
|
|
205
|
+ ;; Tests with NaN, where = should fail.
|
|
206
|
+ (ext:with-float-traps-masked (:invalid)
|
|
207
|
+ (assert-false (dtst-=3 *double-float-nan* 1d0 1d0))
|
|
208
|
+ (assert-false (dtst-=3 1d0 *double-float-nan* 1d0))
|
|
209
|
+ (assert-false (dtst-=3 1d0 1d0 *double-float-nan*)))) |