From: Andrea Corallo Date: Sat, 6 Mar 2021 19:38:00 +0000 (+0100) Subject: Fix `=' propagation to handle -0.0 0.0 case X-Git-Tag: emacs-28.0.90~2727^2~99 X-Git-Url: http://git.eshelyaron.com/gitweb/?a=commitdiff_plain;h=05259c4a238efa40fa66ac51844aa5227b9c576b;p=emacs.git Fix `=' propagation to handle -0.0 0.0 case * lisp/emacs-lisp/comp-cstr.el (comp-cstr-intersection-homogeneous): Fix indent + use `memql'. (comp-cstr-=): Handle 0.0 -0.0 idiosyncrasy * test/src/comp-tests.el (comp-tests-type-spec-tests): Add two tests and fix enumeration. --- diff --git a/lisp/emacs-lisp/comp-cstr.el b/lisp/emacs-lisp/comp-cstr.el index 6a8ec5213d5..d6423efa0d6 100644 --- a/lisp/emacs-lisp/comp-cstr.el +++ b/lisp/emacs-lisp/comp-cstr.el @@ -664,7 +664,7 @@ DST is returned." (cl-return-from comp-cstr-intersection-homogeneous dst)) (setf (neg dst) (when srcs - (neg (car srcs)))) + (neg (car srcs)))) ;; Type propagation. (setf (typeset dst) @@ -682,7 +682,7 @@ DST is returned." ;; If (member value) is subtypep of all other sources then ;; is good to be colleted. when (cl-every (lambda (s) - (or (memq val (valset s)) + (or (memql val (valset s)) (cl-some (lambda (type) (cl-typep val type)) (typeset s)))) @@ -890,6 +890,10 @@ Non memoized version of `comp-cstr-intersection-no-mem'." (cl-return cstr) finally (setf (valset cstr) (append vals-to-add (valset cstr)))) + (when (memql 0.0 (valset cstr)) + (cl-pushnew -0.0 (valset cstr))) + (when (memql -0.0 (valset cstr)) + (cl-pushnew 0.0 (valset cstr))) cstr)) (comp-cstr-intersection dst (relax-cstr op1) (relax-cstr op2))))) diff --git a/test/src/comp-tests.el b/test/src/comp-tests.el index dae2abca7e7..cd1c2e0735e 100644 --- a/test/src/comp-tests.el +++ b/test/src/comp-tests.el @@ -1299,32 +1299,48 @@ Return a list of results." (error ""))) cons) - ;; 69 + ;; 68 ((defun comp-tests-ret-type-spec-f (x) (if (and (floatp x) - (= x 0)) + (= x 1)) x (error ""))) ;; Conservative (see cstr relax in `comp-cstr-='). - (or (member 0.0) (integer 0 0))) + (or (member 1.0) (integer 1 1))) - ;; 70 + ;; 69 ((defun comp-tests-ret-type-spec-f (x) (if (and (integer x) - (= x 0)) + (= x 1)) x (error ""))) ;; Conservative (see cstr relax in `comp-cstr-='). - (or (member 0.0) (integer 0 0))) + (or (member 1.0) (integer 1 1))) - ;; 71 + ;; 70 ((defun comp-tests-ret-type-spec-f (x y) (if (and (floatp x) (integerp y) (= x y)) x (error ""))) - (or float integer)))) + (or float integer)) + + ;; 71 + ((defun comp-tests-ret-type-spec-f (x) + (if (= x 0.0) + x + (error ""))) + (or (member -0.0 0.0) (integer 0 0))) + + ;; 72 + ((defun comp-tests-ret-type-spec-f (x) + (unless (= x 0.0) + (error "")) + (unless (eql x -0.0) + (error "")) + x) + float))) (defun comp-tests-define-type-spec-test (number x) `(comp-deftest ,(intern (format "ret-type-spec-%d" number)) ()