subtypep-float.lsp 11.5 KB
Newer Older
1 2 3 4 5 6 7
;-*- Mode:     Lisp -*-
;;;; Author:   Paul Dietz
;;;; Created:  Sat Feb 15 11:55:37 2003
;;;; Contains: Tests for subtype relationships on float types

(in-package :cl-test)

8 9
(compile-and-load "types-aux.lsp")

10 11 12 13
;;;;;;;

(deftest subtypep.float.1
  (loop for tp in +float-types+
sds's avatar
sds committed
14
        append (check-subtypep tp 'float t t))
15 16 17 18 19
  nil)

(deftest subtypep.float.2
  (if (subtypep 'short-float 'long-float)
      (loop for tp in +float-types+
sds's avatar
sds committed
20 21 22
            append
            (loop for tp2 in +float-types+
                  append (check-subtypep tp tp2 t t)))
23 24 25 26 27
    nil)
  nil)

(deftest subtypep.float.3
  (if (and (not (subtypep 'short-float 'single-float))
sds's avatar
sds committed
28
           (subtypep 'single-float 'long-float))
29 30 31 32 33 34 35 36 37 38 39 40
      (append
       (check-equivalence 'single-float 'double-float)
       (check-equivalence 'single-float 'long-float)
       (check-equivalence 'double-float 'long-float)
       (classes-are-disjoint 'short-float 'single-float)
       (classes-are-disjoint 'short-float 'double-float)
       (classes-are-disjoint 'short-float 'long-float))
    nil)
  nil)

(deftest subtypep.float.4
  (if (and (subtypep 'single-float 'short-float)
sds's avatar
sds committed
41 42
           (subtypep 'double-float 'long-float)
           (not (subtypep 'short-float 'double-float)))
43 44 45 46
      (append
       (check-equivalence 'short-float 'single-float)
       (check-equivalence 'double-float 'long-float)
       (loop for tp in '(short-float single-float)
sds's avatar
sds committed
47 48 49
             append
             (loop for tp2 in '(double-float long-float)
                   append (classes-are-disjoint tp tp2))))
50 51 52 53 54
    nil)
  nil)

(deftest subtypep.float.5
  (if (and (not (subtypep 'single-float 'short-float))
sds's avatar
sds committed
55 56
           (not (subtypep 'single-float 'double-float))
           (subtypep 'double-float 'long-float))
57 58 59 60 61 62 63 64 65 66 67 68
      (append
       (classes-are-disjoint 'short-float 'single-float)
       (classes-are-disjoint 'short-float 'double-float)
       (classes-are-disjoint 'short-float 'long-float)
       (classes-are-disjoint 'single-float 'double-float)
       (classes-are-disjoint 'single-float 'long-float)
       (check-equivalence 'double-float 'long-float))
    nil)
  nil)

(deftest subtypep.float.6
  (if (and (subtypep 'single-float 'short-float)
sds's avatar
sds committed
69 70
           (not (subtypep 'single-float 'double-float))
           (not (subtypep 'double-float 'long-float)))
71 72 73 74 75 76 77 78 79 80
      (append
       (check-equivalence 'short-float 'single-float)
       (classes-are-disjoint 'single-float 'double-float)
       (classes-are-disjoint 'single-float 'long-float)
       (classes-are-disjoint 'double-float 'long-float))
    nil)
  nil)

(deftest subtypep.float.7
  (if (and (not (subtypep 'single-float 'short-float))
sds's avatar
sds committed
81 82
           (not (subtypep 'single-float 'double-float))
           (not (subtypep 'double-float 'long-float)))
83
      (loop for tp in +float-types+
sds's avatar
sds committed
84 85 86 87
            append
            (loop for tp2 in +float-types+
                  unless (eq tp tp2)
                  append (classes-are-disjoint tp tp2)))
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
    nil)
  nil)

(deftest subtypep.float.8
  (subtypep* '(short-float 0.0s0 10.0s0) '(short-float 0.0s0 11.0s0))
  t t)

(deftest subtypep.float.9
  (subtypep* '(single-float 0.0f0 10.0f0) '(single-float 0.0f0 11.0f0))
  t t)

(deftest subtypep.float.10
  (subtypep* '(double-float 0.0d0 10.0d0) '(double-float 0.0d0 11.0d0))
  t t)

(deftest subtypep.float.11
  (subtypep* '(long-float 0.0l0 10.0l0) '(long-float 0.0l0 11.0l0))
  t t)

(deftest subtypep.float.12
  (subtypep* '(short-float 0.0s0 11.0s0) '(short-float 0.0s0 10.0s0))
  nil t)

(deftest subtypep.float.13
  (subtypep* '(single-float 0.0f0 11.0f0) '(single-float 0.0f0 10.0f0))
  nil t)

(deftest subtypep.float.14
  (subtypep* '(double-float 0.0d0 11.0d0) '(double-float 0.0d0 10.0d0))
  nil t)

(deftest subtypep.float.15
  (subtypep* '(long-float 0.0l0 11.0l0) '(long-float 0.0l0 10.0l0))
  nil t)

(deftest subtypep.float.16
  (subtypep* '(short-float 0.0s0 (10.0s0)) '(short-float 0.0s0 10.0s0))
  t t)

(deftest subtypep.float.17
  (subtypep* '(single-float 0.0f0 (10.0f0)) '(single-float 0.0f0 10.0f0))
  t t)

(deftest subtypep.float.18
  (subtypep* '(double-float 0.0d0 (10.0d0)) '(double-float 0.0d0 10.0d0))
  t t)

(deftest subtypep.float.19
  (subtypep* '(long-float 0.0l0 (10.0l0)) '(long-float 0.0l0 10.0l0))
  t t)

(deftest subtypep.float.20
  (subtypep* '(short-float 0.0s0 10.0s0) '(short-float 0.0s0 (10.0s0)))
  nil t)

(deftest subtypep.float.21
  (subtypep* '(single-float 0.0f0 10.0f0) '(single-float 0.0f0 (10.0f0)))
  nil t)

(deftest subtypep.float.22
  (subtypep* '(double-float 0.0d0 10.0d0) '(double-float 0.0d0 (10.0d0)))
  nil t)

(deftest subtypep.float.23
  (subtypep* '(long-float 0.0l0 10.0l0) '(long-float 0.0l0 (10.0l0)))
  nil t)

(deftest subtypep.float.24
  (check-equivalence '(and (short-float 0.0s0 2.0s0)
sds's avatar
sds committed
157 158
                           (short-float 1.0s0 3.0s0))
                     '(short-float 1.0s0 2.0s0))
159 160 161 162
  nil)

(deftest subtypep.float.25
  (check-equivalence '(and (single-float 0.0f0 2.0f0)
sds's avatar
sds committed
163 164
                           (single-float 1.0f0 3.0f0))
                     '(single-float 1.0f0 2.0f0))
165 166 167 168
  nil)

(deftest subtypep.float.26
  (check-equivalence '(and (double-float 0.0d0 2.0d0)
sds's avatar
sds committed
169 170
                           (double-float 1.0d0 3.0d0))
                     '(double-float 1.0d0 2.0d0))
171 172 173 174
  nil)

(deftest subtypep.float.27
  (check-equivalence '(and (long-float 0.0l0 2.0l0)
sds's avatar
sds committed
175 176
                           (long-float 1.0l0 3.0l0))
                     '(long-float 1.0l0 2.0l0))
177
  nil)
178 179 180 181 182

;;; Signed zero tests

(deftest subtypep.short-float.zero.1
  (check-equivalence '(short-float 0.0s0 *)
sds's avatar
sds committed
183 184
                     '(or (short-float (0.0s0) *)
                          (member -0.0s0 0.0s0)))
185 186 187
  nil)

(unless (eql 0.0s0 -0.0s0)
pfdietz's avatar
pfdietz committed
188
  (deftest subtypep.short-float.zero.2a
189
    (values (subtypep '(short-float 0.0s0)
sds's avatar
sds committed
190
                      '(or (short-float (0.0s0)) (member 0.0s0))))
191
    nil)
pfdietz's avatar
pfdietz committed
192
  (deftest subtypep.short-float.zero.2b
193
    (values (subtypep '(short-float 0.0s0)
sds's avatar
sds committed
194
                      '(or (short-float (0.0s0)) (member -0.0s0))))
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266
    nil))

(deftest subtypep.short-float.zero.3
  (subtypep* '(short-float -0.0s0 *) '(short-float 0.0s0 *))
  t t)

(deftest subtypep.short-float.zero.4
  (subtypep* '(short-float * -0.0s0) '(short-float * 0.0s0))
  t t)

(deftest subtypep.short-float.zero.5
  (subtypep* '(short-float (-0.0s0) *) '(short-float (0.0s0) *))
  t t)

(deftest subtypep.short-float.zero.6
  (subtypep* '(short-float * (-0.0s0)) '(short-float * (0.0s0)))
  t t)

(deftest subtypep.short-float.zero.7
  (subtypep* '(short-float 0.0s0 *) '(short-float -0.0s0 *))
  t t)

(deftest subtypep.short-float.zero.8
  (subtypep* '(short-float * 0.0s0) '(short-float * -0.0s0))
  t t)

(deftest subtypep.short-float.zero.9
  (subtypep* '(short-float (0.0s0) *) '(short-float (-0.0s0) *))
  t t)

(deftest subtypep.short-float.zero.10
  (subtypep* '(short-float * (0.0s0)) '(short-float * (-0.0s0)))
  t t)

;;;

(deftest subtypep.float.zero.3
  (subtypep* '(float -0.0 *) '(float 0.0 *))
  t t)

(deftest subtypep.float.zero.4
  (subtypep* '(float * -0.0) '(float * 0.0))
  t t)

(deftest subtypep.float.zero.5
  (subtypep* '(float (-0.0) *) '(float (0.0) *))
  t t)

(deftest subtypep.float.zero.6
  (subtypep* '(float * (-0.0)) '(float * (0.0)))
  t t)

(deftest subtypep.float.zero.7
  (subtypep* '(float 0.0 *) '(float -0.0 *))
  t t)

(deftest subtypep.float.zero.8
  (subtypep* '(float * 0.0) '(float * -0.0))
  t t)

(deftest subtypep.float.zero.9
  (subtypep* '(float (0.0) *) '(float (-0.0) *))
  t t)

(deftest subtypep.float.zero.10
  (subtypep* '(float * (0.0)) '(float * (-0.0)))
  t t)

;;;

(deftest subtypep.single-float.zero.1
  (check-equivalence '(single-float 0.0f0 *)
sds's avatar
sds committed
267 268
                     '(or (single-float (0.0f0) *)
                          (member -0.0f0 0.0f0)))
269 270 271
  nil)

(unless (eql 0.0f0 -0.0f0)
272
  (deftest subtypep.single-float.zero.2a
273
    (values (subtypep '(single-float 0.0f0)
sds's avatar
sds committed
274
                      '(or (single-float (0.0f0)) (member 0.0f0))))
275
    nil)
276
  (deftest subtypep.single-float.zero.2b
277
    (values (subtypep '(single-float 0.0f0)
sds's avatar
sds committed
278
                      '(or (single-float (0.0f0)) (member -0.0f0))))
279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316
    nil))

(deftest subtypep.single-float.zero.3
  (subtypep* '(single-float -0.0f0 *) '(single-float 0.0f0 *))
  t t)

(deftest subtypep.single-float.zero.4
  (subtypep* '(single-float * -0.0f0) '(single-float * 0.0f0))
  t t)

(deftest subtypep.single-float.zero.5
  (subtypep* '(single-float (-0.0f0) *) '(single-float (0.0f0) *))
  t t)

(deftest subtypep.single-float.zero.6
  (subtypep* '(single-float * (-0.0f0)) '(single-float * (0.0f0)))
  t t)

(deftest subtypep.single-float.zero.7
  (subtypep* '(single-float 0.0f0 *) '(single-float -0.0f0 *))
  t t)

(deftest subtypep.single-float.zero.8
  (subtypep* '(single-float * 0.0f0) '(single-float * -0.0f0))
  t t)

(deftest subtypep.single-float.zero.9
  (subtypep* '(single-float (0.0f0) *) '(single-float (-0.0f0) *))
  t t)

(deftest subtypep.single-float.zero.10
  (subtypep* '(single-float * (0.0f0)) '(single-float * (-0.0f0)))
  t t)

;;;

(deftest subtypep.long-float.zero.1
  (check-equivalence '(long-float 0.0l0 *)
sds's avatar
sds committed
317 318
                     '(or (long-float (0.0l0) *)
                          (member -0.0l0 0.0l0)))
319 320 321
  nil)

(unless (eql 0.0l0 -0.0l0)
322
  (deftest subtypep.long-float.zero.2a
323
    (values (subtypep '(long-float 0.0l0)
sds's avatar
sds committed
324
                      '(or (long-float (0.0l0)) (member 0.0l0))))
325
    nil)
326
  (deftest subtypep.long-float.zero.2b
327
    (values (subtypep '(long-float 0.0l0)
sds's avatar
sds committed
328
                      '(or (long-float (0.0l0)) (member -0.0l0))))
329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366
    nil))

(deftest subtypep.long-float.zero.3
  (subtypep* '(long-float -0.0l0 *) '(long-float 0.0l0 *))
  t t)

(deftest subtypep.long-float.zero.4
  (subtypep* '(long-float * -0.0l0) '(long-float * 0.0l0))
  t t)

(deftest subtypep.long-float.zero.5
  (subtypep* '(long-float (-0.0l0) *) '(long-float (0.0l0) *))
  t t)

(deftest subtypep.long-float.zero.6
  (subtypep* '(long-float * (-0.0l0)) '(long-float * (0.0l0)))
  t t)

(deftest subtypep.long-float.zero.7
  (subtypep* '(long-float 0.0l0 *) '(long-float -0.0l0 *))
  t t)

(deftest subtypep.long-float.zero.8
  (subtypep* '(long-float * 0.0l0) '(long-float * -0.0l0))
  t t)

(deftest subtypep.long-float.zero.9
  (subtypep* '(long-float (0.0l0) *) '(long-float (-0.0l0) *))
  t t)

(deftest subtypep.long-float.zero.10
  (subtypep* '(long-float * (0.0l0)) '(long-float * (-0.0l0)))
  t t)

;;;

(deftest subtypep.double-float.zero.1
  (check-equivalence '(double-float 0.0d0 *)
sds's avatar
sds committed
367 368
                     '(or (double-float (0.0d0) *)
                          (member -0.0d0 0.0d0)))
369 370 371
  nil)

(unless (eql 0.0d0 -0.0d0)
372
  (deftest subtypep.double-float.zero.2a
373
    (values (subtypep '(double-float 0.0d0)
sds's avatar
sds committed
374
                      '(or (double-float (0.0d0)) (member 0.0d0))))
375
    nil)
376
  (deftest subtypep.double-float.zero.2b
377
    (values (subtypep '(double-float 0.0d0)
sds's avatar
sds committed
378
                      '(or (double-float (0.0d0)) (member -0.0d0))))
379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411
    nil))

(deftest subtypep.double-float.zero.3
  (subtypep* '(double-float -0.0d0 *) '(double-float 0.0d0 *))
  t t)

(deftest subtypep.double-float.zero.4
  (subtypep* '(double-float * -0.0d0) '(double-float * 0.0d0))
  t t)

(deftest subtypep.double-float.zero.5
  (subtypep* '(double-float (-0.0d0) *) '(double-float (0.0d0) *))
  t t)

(deftest subtypep.double-float.zero.6
  (subtypep* '(double-float * (-0.0d0)) '(double-float * (0.0d0)))
  t t)

(deftest subtypep.double-float.zero.7
  (subtypep* '(double-float 0.0d0 *) '(double-float -0.0d0 *))
  t t)

(deftest subtypep.double-float.zero.8
  (subtypep* '(double-float * 0.0d0) '(double-float * -0.0d0))
  t t)

(deftest subtypep.double-float.zero.9
  (subtypep* '(double-float (0.0d0) *) '(double-float (-0.0d0) *))
  t t)

(deftest subtypep.double-float.zero.10
  (subtypep* '(double-float * (0.0d0)) '(double-float * (-0.0d0)))
  t t)