1 ;;;; This file is for floating-point-related tests which have side
2 ;;;; effects (e.g. executing DEFUN).
4 ;;;; This software is part of the SBCL system. See the README file for
7 ;;;; While most of SBCL is derived from the CMU CL system, the test
8 ;;;; files (like this one) were written from scratch after the fork
11 ;;;; This software is in the public domain and is provided with
12 ;;;; absolutely no warranty. See the COPYING and CREDITS files for
13 ;;;; more information.
15 (cl:in-package :cl-user)
17 ;;; Hannu Rummukainen reported a CMU CL bug on cmucl-imp@cons.org 26
18 ;;; Jun 2000. This is the test case for it.
20 ;;; The bug was listed as "39: .. Probably the same bug exists in
21 ;;; SBCL" for a while until Martin Atzmueller showed that it's not
22 ;;; present after all, presumably because the bug was introduced into
23 ;;; CMU CL after the fork. But we'll test for it anyway, in case
24 ;;; e.g. someone inadvertently ports the bad code.
27 :element-type 'double-float
28 :initial-contents (list x y)))
30 (declaim (inline point39-x point39-y))
32 (declare (type (simple-array double-float (2)) p))
35 (declare (type (simple-array double-float (2)) p))
37 (defun order39 (points)
38 (sort points (lambda (p1 p2)
39 (let* ((y1 (point39-y p1))
46 (order39 (make-array 4
47 :initial-contents (list (point39 0.0d0 0.0d0)
50 (point39 3.0d0 3.0d0)))))
51 (assert (equalp (test39)
57 (defun complex-double-float-ppc (x y)
58 (declare (type (complex double-float) x y))
59 (declare (optimize speed))
61 (compile 'complex-double-float-ppc)
62 (assert (= (complex-double-float-ppc #c(0.0d0 1.0d0) #c(2.0d0 3.0d0))
65 (defun single-float-ppc (x)
66 (declare (type (signed-byte 32) x) (optimize speed))
68 (compile 'single-float-ppc)
69 (assert (= (single-float-ppc -30) -30f0))
71 ;;; constant-folding irrational functions
74 ;; do not remove the ECASE here: the bug this checks for indeed
75 ;; depended on this configuration
76 (ecase x (1 least-positive-double-float)))
77 (macrolet ((test (fun)
78 (let ((name (intern (format nil "TEST-CONSTANT-~A" fun))))
80 (defun ,name () (,fun (df 1)))
98 ;;; Broken move-arg-double-float for non-rsp frame pointers on x86-64
100 (declare (optimize speed))
101 (multiple-value-bind (x)
103 (declare (double-float x))
110 (format t "y=~s~%" y)))
115 (assert (= (test 1.0d0) 2.0d0))
117 (deftype myarraytype (&optional (length '*))
118 `(simple-array double-float (,length)))
119 (defun new-pu-label-from-pu-labels (array)
120 (setf (aref (the myarraytype array) 0)
121 sb-ext:double-float-positive-infinity))
125 ;;; FIXME: it may be that TYPE-ERROR is wrong, and we should
126 ;;; instead signal an overflow or coerce into an infinity.
128 (loop for n from (expt 2 1024) upto (+ 10 (expt 2 1024))
130 (coerce n 'single-float)
131 (simple-type-error ()
132 (return-from bug-407a :type-error)))))
133 (assert (eq :type-error (bug-407a)))
135 (loop for n from (expt 2 1024) upto (+ 10 (expt 2 1024))
137 (format t "~E~%" (coerce n 'single-float))
138 (simple-type-error ()
139 (return-from bug-407b :type-error)))))
140 (assert (eq :type-error (bug-407b)))
142 ;; 1.0.29.44 introduces a ton of changes for complex floats
143 ;; on x86-64. Huge test of doom to help catch weird corner
145 ;; Abuse the framework to also test some float arithmetic
146 ;; changes wrt constant arguments in 1.0.29.54.
147 (defmacro def-compute (name real-type
148 &optional (complex-type `(complex ,real-type)))
149 `(defun ,name (x y r)
150 (declare (type ,complex-type x y)
152 (flet ((reflections (x)
155 (complex (- (realpart x)) (imagpart x))
158 (declare (type ,complex-type x y)
160 (list (1+ x) (* 2 x) (/ x 2) (= 1 x)
161 (+ x y) (+ r x) (+ x r)
162 (- x y) (- r x) (- x r)
163 (* x y) (* x r) (* r x)
170 (conjugate x) (conjugate r)
171 (abs r) (- r) (= 1 r)
172 (- x) (1+ r) (* 2 r) (/ r 2)
173 (complex r) (complex r r) (complex 0 r)
174 (= x y) (= r x) (= y r) (= x (complex 0 r))
175 (= r (realpart x)) (= (realpart x) r)
176 (> r (realpart x)) (< r (realpart x))
177 (> (realpart x) r) (< (realpart x) r)
178 (eql x y) (eql x (complex r)) (eql y (complex r))
179 (eql x (complex r r)) (eql y (complex 0 r))
180 (eql r (realpart x)) (eql (realpart x) r))))
181 (declare (inline reflections))
182 (multiple-value-bind (x1 x2 x3 x4) (reflections x)
183 (multiple-value-bind (y1 y2 y3 y4) (reflections y)
184 #.(let ((form '(list)))
185 (dolist (x '(x1 x2 x3 x4) (reverse form))
186 (dolist (y '(y1 y2 y3 y4))
188 (append (compute ,x ,y r)
189 (compute ,x ,y (- r))))
192 (def-compute compute-number real number)
193 (def-compute compute-single single-float)
194 (def-compute compute-double double-float)
196 (labels ((equal-enough (x y)
200 (or (eql (coerce x '(complex double-float))
201 (coerce y '(complex double-float)))
202 (and (equal-enough (realpart x) (realpart y))
203 (equal-enough (imagpart x) (imagpart y)))))
205 (or (eql (coerce x 'double-float) (coerce y 'double-float))
206 (< (abs (- x y)) 1d-5))))))
207 (let* ((reals '(0 1 2))
208 (complexes '#.(let ((reals '(0 1 2))
210 (dolist (x reals (nreverse cpx))
212 (push (complex x y) cpx))))))
213 (declare (notinline every))
215 (dolist (x complexes)
216 (dolist (y complexes)
217 (let ((value (compute-number x y r))
218 (single (compute-single (coerce x '(complex single-float))
219 (coerce y '(complex single-float))
220 (coerce r 'single-float)))
221 (double (compute-double (coerce x '(complex double-float))
222 (coerce y '(complex double-float))
223 (coerce r 'double-float))))
224 (assert (every (lambda (pos ref single double)
225 (declare (ignorable pos))
226 (every (lambda (ref single double)
227 (or (and (equal-enough ref single)
228 (equal-enough ref double))
229 (and (not (numberp single)) ;; -ve 0s
230 (equal-enough single double))))
231 (fourth ref) (fourth single) (fourth double)))
232 '((0 0) (0 1) (0 2) (0 3)
233 (1 0) (1 1) (1 2) (1 3)
234 (2 0) (2 1) (2 2) (2 3)
235 (3 0) (3 1) (3 2) (3 3))
236 value single double))))))))