From 64eb9b71da7c3c34541929c1b0dfb7f0c11d3d88 Mon Sep 17 00:00:00 2001 From: Paul Eggert Date: Fri, 17 Aug 2018 00:25:20 -0700 Subject: Fix problems with logxor etc. and fixnums MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit These operations incorrectly treated negative fixnums as bignums greater than most-positive-fixnum. * src/alloc.c (mpz_set_intmax_slow): Avoid undefined behavior if signed unary negation overflows, while we’re in the neighborhood. (mpz_set_uintmax_slow): Remove. All uses removed. * src/data.c (arith_driver): Treat fixnums as signed, not unsigned, even for logical operations. * src/lisp.h (mpz_set_uintmax): Remove. All uses removed. * test/src/data-tests.el (data-tests-logand) (data-tests-logior, data-tests-logxor): New tests. --- test/src/data-tests.el | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/src/data-tests.el') diff --git a/test/src/data-tests.el b/test/src/data-tests.el index 82649022576..a4c6b0e4915 100644 --- a/test/src/data-tests.el +++ b/test/src/data-tests.el @@ -597,9 +597,23 @@ comparing the subr with a much slower lisp implementation." (should (< (1- most-negative-fixnum) most-negative-fixnum)) (should (fixnump (1- (1+ most-positive-fixnum))))) +(ert-deftest data-tests-logand () + (should (= -1 (logand -1))) + (let ((n (* 2 most-negative-fixnum))) + (should (= (logand -1 n) n)))) + (ert-deftest data-tests-logcount () (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128))) +(ert-deftest data-tests-logior () + (should (= -1 (logior -1))) + (should (= -1 (logior most-positive-fixnum most-negative-fixnum)))) + +(ert-deftest data-tests-logxor () + (should (= -1 (logxor -1))) + (let ((n (1+ most-positive-fixnum))) + (should (= (logxor -1 n) (lognot n))))) + (ert-deftest data-tests-minmax () (let ((a (- most-negative-fixnum 1)) (b (+ most-positive-fixnum 1)) -- cgit v1.2.1