aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTom Tromey2018-07-07 14:22:44 -0600
committerTom Tromey2018-07-12 22:12:27 -0600
commita770fb44288c75fa2b0471ceaf00bf741376e40f (patch)
tree263136cf11b50104797d7642247b87fab2814ded
parentc7e393bc4130c871a92fef7e9ac0c7c1832aa614 (diff)
downloademacs-a770fb44288c75fa2b0471ceaf00bf741376e40f.tar.gz
emacs-a770fb44288c75fa2b0471ceaf00bf741376e40f.zip
Make logcount handle bignums
* src/data.c (Flogcount): Handle bignums. * test/src/data-tests.el (data-tests-logcount): New test.
-rw-r--r--src/data.c17
-rw-r--r--test/src/data-tests.el3
2 files changed, 19 insertions, 1 deletions
diff --git a/src/data.c b/src/data.c
index c9504694e37..2e366b5313f 100644
--- a/src/data.c
+++ b/src/data.c
@@ -3184,7 +3184,22 @@ of VALUE. If VALUE is negative, return the number of zero bits in the
3184representation. */) 3184representation. */)
3185 (Lisp_Object value) 3185 (Lisp_Object value)
3186{ 3186{
3187 CHECK_FIXNUM (value); 3187 CHECK_INTEGER (value);
3188
3189 if (BIGNUMP (value))
3190 {
3191 if (mpz_cmp_si (XBIGNUM (value)->value, 0) >= 0)
3192 return make_fixnum (mpz_popcount (XBIGNUM (value)->value));
3193 mpz_t tem;
3194 mpz_init (tem);
3195 mpz_neg (tem, XBIGNUM (value)->value);
3196 mpz_sub_ui (tem, tem, 1);
3197 Lisp_Object result = make_fixnum (mpz_popcount (tem));
3198 mpz_clear (tem);
3199 return result;
3200 }
3201
3202 eassume (FIXNUMP (value));
3188 EMACS_INT v = XINT (value) < 0 ? -1 - XINT (value) : XINT (value); 3203 EMACS_INT v = XINT (value) < 0 ? -1 - XINT (value) : XINT (value);
3189 return make_fixnum (EMACS_UINT_WIDTH <= UINT_WIDTH 3204 return make_fixnum (EMACS_UINT_WIDTH <= UINT_WIDTH
3190 ? count_one_bits (v) 3205 ? count_one_bits (v)
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index dd6ce196f96..561b7bd9ca6 100644
--- a/test/src/data-tests.el
+++ b/test/src/data-tests.el
@@ -587,4 +587,7 @@ comparing the subr with a much slower lisp implementation."
587 (should (< (1- most-negative-fixnum) most-negative-fixnum)) 587 (should (< (1- most-negative-fixnum) most-negative-fixnum))
588 (should (fixnump (1- (1+ most-positive-fixnum))))) 588 (should (fixnump (1- (1+ most-positive-fixnum)))))
589 589
590(ert-deftest data-tests-logcount ()
591 (should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128)))
592
590;;; data-tests.el ends here 593;;; data-tests.el ends here