summaryrefslogtreecommitdiff
path: root/test/src/data-tests.el
diff options
context:
space:
mode:
authorPaul Eggert <eggert@cs.ucla.edu>2017-09-30 15:36:52 -0700
committerPaul Eggert <eggert@cs.ucla.edu>2017-09-30 15:38:14 -0700
commit8136df6a8cbf071266eb38f5baef005f4e9241a3 (patch)
tree4ade7520c5be858be40b7939a0338e4a48288c85 /test/src/data-tests.el
parentd247e1d30abcb77665f829ca98a5bdef69ff4bc3 (diff)
downloademacs-8136df6a8cbf071266eb38f5baef005f4e9241a3.tar.gz
Make logcount act like CL on negative arg
Behaving like Common Lisp is less likely to lead to surprises, as it yields the same answers on 32- vs 64-bit machines. * doc/lispref/numbers.texi (Bitwise Operations): Document behavior on negative integers. * src/data.c (Flogcount): Behave like Common Lisp for negative arguments. * test/src/data-tests.el (data-tests-popcnt) (data-tests-logcount): Test negative args too.
Diffstat (limited to 'test/src/data-tests.el')
-rw-r--r--test/src/data-tests.el4
1 files changed, 3 insertions, 1 deletions
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index d1154cc5c44..374d1689b9e 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -109,12 +109,14 @@
(defun data-tests-popcnt (byte)
"Calculate the Hamming weight of BYTE."
+ (if (< byte 0)
+ (setq byte (lognot byte)))
(setq byte (- byte (logand (lsh byte -1) #x55555555)))
(setq byte (+ (logand byte #x33333333) (logand (lsh byte -2) #x33333333)))
(lsh (* (logand (+ byte (lsh byte -4)) #x0f0f0f0f) #x01010101) -24))
(ert-deftest data-tests-logcount ()
- (should (cl-loop for n in (number-sequence 0 255)
+ (should (cl-loop for n in (number-sequence -255 255)
always (= (logcount n) (data-tests-popcnt n))))
;; https://oeis.org/A000120
(should (= 11 (logcount 9727)))