1 ;;;; floating-point-related tests with no side effects
3 ;;;; This software is part of the SBCL system. See the README file for
6 ;;;; While most of SBCL is derived from the CMU CL system, the test
7 ;;;; files (like this one) were written from scratch after the fork
10 ;;;; This software is in the public domain and is provided with
11 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
12 ;;;; more information.
14 (cl:in-package
:cl-user
)
16 (dolist (ifnis (list (cons single-float-positive-infinity
17 single-float-negative-infinity
)
18 (cons double-float-positive-infinity
19 double-float-negative-infinity
)))
20 (destructuring-bind (+ifni . -ifni
) ifnis
21 (assert (= (* +ifni
1) +ifni
))
22 (assert (= (* +ifni -
0.1) -ifni
))
23 (assert (= (+ +ifni -
0.1) +ifni
))
24 (assert (= (- +ifni -
0.1) +ifni
))
25 (assert (= (sqrt +ifni
) +ifni
))
26 (assert (= (* -ifni -
14) +ifni
))
27 (assert (= (/ -ifni
0.1) -ifni
))
28 (assert (= (/ -ifni
100/3) -ifni
))
29 (assert (not (= +ifni -ifni
)))
30 (assert (= -ifni -ifni
))
31 (assert (not (= +ifni
100/3)))
32 (assert (not (= -ifni -
1.0 -ifni
)))
33 (assert (not (= -ifni -
17/02 -ifni
)))
34 (assert (< -ifni
+ifni
))
35 (assert (not (< +ifni
100)))
36 (assert (not (< +ifni
100.0)))
37 (assert (not (< +ifni -ifni
)))
38 (assert (< 100 +ifni
))
39 (assert (< 100.0 +ifni
))
40 (assert (>= 100 -ifni
))
41 (assert (not (<= 6/7 (* 3 -ifni
))))
42 (assert (not (> +ifni
+ifni
)))))
44 ;;; ANSI: FLOAT-RADIX should signal an error if its argument is not a
47 ;;; (Peter Van Eynde's ansi-test suite caught this, and Eric Marsden
48 ;;; reported a fix for CMU CL, which was ported to sbcl-0.6.12.35.)
49 (assert (typep (nth-value 1 (ignore-errors (float-radix "notfloat")))
52 (assert (typep (nth-value 1 (ignore-errors
53 (funcall (fdefinition 'float-radix
) "notfloat")))
56 ;;; Before 0.8.2.14 the cross compiler failed to work with
57 ;;; denormalized numbers
58 (when (subtypep 'single-float
'short-float
)
59 (assert (eql least-positive-single-float least-positive-short-float
)))
62 (let ((f (eval 'least-positive-double-float
)))
63 (assert (eql (multiple-value-bind (signif expon sign
)
64 (integer-decode-float f
)
65 (scale-float (float signif f
) expon
))
68 ;;; bug found by Paul Dietz: FFLOOR and similar did not work for integers
69 (let ((tests '(((ffloor -
8 3) (-3.0
1))
70 ((fround -
8 3) (-3.0
1))
71 ((ftruncate -
8 3) (-2.0 -
2))
72 ((fceiling -
8 3) (-2.0 -
2)))))
73 (loop for
(exp res
) in tests
74 for real-res
= (multiple-value-list (eval exp
))
75 do
(assert (equal real-res res
))))
77 ;;; bug 45b reported by PVE
78 (dolist (type '(short single double long
))
79 (dolist (sign '(positive negative
))
80 (let* ((name (find-symbol (format nil
"LEAST-~A-~A-FLOAT"
83 (value (symbol-value name
)))
84 (assert (zerop (/ value
2))))))
86 ;;; bug found by Paul Dietz: bad rounding on small floats
87 (assert (= (fround least-positive-short-float least-positive-short-float
) 1.0))