aboutsummaryrefslogtreecommitdiffstats
path: root/test/src
diff options
context:
space:
mode:
Diffstat (limited to 'test/src')
-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 @@
109 109
110(defun data-tests-popcnt (byte) 110(defun data-tests-popcnt (byte)
111 "Calculate the Hamming weight of BYTE." 111 "Calculate the Hamming weight of BYTE."
112 (if (< byte 0)
113 (setq byte (lognot byte)))
112 (setq byte (- byte (logand (lsh byte -1) #x55555555))) 114 (setq byte (- byte (logand (lsh byte -1) #x55555555)))
113 (setq byte (+ (logand byte #x33333333) (logand (lsh byte -2) #x33333333))) 115 (setq byte (+ (logand byte #x33333333) (logand (lsh byte -2) #x33333333)))
114 (lsh (* (logand (+ byte (lsh byte -4)) #x0f0f0f0f) #x01010101) -24)) 116 (lsh (* (logand (+ byte (lsh byte -4)) #x0f0f0f0f) #x01010101) -24))
115 117
116(ert-deftest data-tests-logcount () 118(ert-deftest data-tests-logcount ()
117 (should (cl-loop for n in (number-sequence 0 255) 119 (should (cl-loop for n in (number-sequence -255 255)
118 always (= (logcount n) (data-tests-popcnt n)))) 120 always (= (logcount n) (data-tests-popcnt n))))
119 ;; https://oeis.org/A000120 121 ;; https://oeis.org/A000120
120 (should (= 11 (logcount 9727))) 122 (should (= 11 (logcount 9727)))