mirror of
git://git.sv.gnu.org/emacs.git
synced 2026-04-18 03:51:48 -07:00
Make logcount handle bignums
* src/data.c (Flogcount): Handle bignums. * test/src/data-tests.el (data-tests-logcount): New test.
This commit is contained in:
parent
c7e393bc41
commit
a770fb4428
2 changed files with 19 additions and 1 deletions
17
src/data.c
17
src/data.c
|
|
@ -3184,7 +3184,22 @@ of VALUE. If VALUE is negative, return the number of zero bits in the
|
|||
representation. */)
|
||||
(Lisp_Object value)
|
||||
{
|
||||
CHECK_FIXNUM (value);
|
||||
CHECK_INTEGER (value);
|
||||
|
||||
if (BIGNUMP (value))
|
||||
{
|
||||
if (mpz_cmp_si (XBIGNUM (value)->value, 0) >= 0)
|
||||
return make_fixnum (mpz_popcount (XBIGNUM (value)->value));
|
||||
mpz_t tem;
|
||||
mpz_init (tem);
|
||||
mpz_neg (tem, XBIGNUM (value)->value);
|
||||
mpz_sub_ui (tem, tem, 1);
|
||||
Lisp_Object result = make_fixnum (mpz_popcount (tem));
|
||||
mpz_clear (tem);
|
||||
return result;
|
||||
}
|
||||
|
||||
eassume (FIXNUMP (value));
|
||||
EMACS_INT v = XINT (value) < 0 ? -1 - XINT (value) : XINT (value);
|
||||
return make_fixnum (EMACS_UINT_WIDTH <= UINT_WIDTH
|
||||
? count_one_bits (v)
|
||||
|
|
|
|||
|
|
@ -587,4 +587,7 @@ 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-logcount ()
|
||||
(should (= (logcount (read "#xffffffffffffffffffffffffffffffff")) 128)))
|
||||
|
||||
;;; data-tests.el ends here
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue