[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Emacs-diffs] feature/bignum a770fb4 16/24: Make logcount handle bignums
From: |
Tom Tromey |
Subject: |
[Emacs-diffs] feature/bignum a770fb4 16/24: Make logcount handle bignums |
Date: |
Fri, 13 Jul 2018 00:25:09 -0400 (EDT) |
branch: feature/bignum
commit a770fb44288c75fa2b0471ceaf00bf741376e40f
Author: Tom Tromey <address@hidden>
Commit: Tom Tromey <address@hidden>
Make logcount handle bignums
* src/data.c (Flogcount): Handle bignums.
* test/src/data-tests.el (data-tests-logcount): New test.
---
src/data.c | 17 ++++++++++++++++-
test/src/data-tests.el | 3 +++
2 files changed, 19 insertions(+), 1 deletion(-)
diff --git a/src/data.c b/src/data.c
index c950469..2e366b5 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
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)
diff --git a/test/src/data-tests.el b/test/src/data-tests.el
index dd6ce19..561b7bd 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."
(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
- [Emacs-diffs] branch feature/bignum created (now cc3d758), Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum eefa65e 07/24: Make comparison operators handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum b2f3f4e 04/24: Provide new functions to create bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 580d173 05/24: Make eql work for bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum a0f2adb 03/24: Introduce the bignum type, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 23eab9a 10/24: Make number-to-string work for bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 025adce 13/24: Make abs handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 6d4bf2c 09/24: Add some bignum tests, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 872faab 12/24: Allow conversion of bignums to floats, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 5875fba 08/24: Make arithmetic work with bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum a770fb4 16/24: Make logcount handle bignums,
Tom Tromey <=
- [Emacs-diffs] feature/bignum 0d86891 14/24: Make 1+ and 1- handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 8fb995b 17/24: Make min and max handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 3dea8f8 19/24: Make % and mod handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum d14808c 11/24: Make format handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum c7e393b 15/24: Make lognot handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 1e8ae6c 06/24: Make the reader accept bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum 27980e3 21/24: Make ash and lsh handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum cca0e79 20/24: Make logb handle bignums, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum d0fac17 18/24: Let C modules access bignum values, Tom Tromey, 2018/07/13
- [Emacs-diffs] feature/bignum e2a78b0 23/24: Bignum fixes for byte-compiler and bytecode interpreter, Tom Tromey, 2018/07/13