diff options
| author | Paul Eggert | 2017-09-30 15:36:52 -0700 |
|---|---|---|
| committer | Paul Eggert | 2017-09-30 15:38:14 -0700 |
| commit | 8136df6a8cbf071266eb38f5baef005f4e9241a3 (patch) | |
| tree | 4ade7520c5be858be40b7939a0338e4a48288c85 /src/data.c | |
| parent | d247e1d30abcb77665f829ca98a5bdef69ff4bc3 (diff) | |
| download | emacs-8136df6a8cbf071266eb38f5baef005f4e9241a3.tar.gz emacs-8136df6a8cbf071266eb38f5baef005f4e9241a3.zip | |
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 'src/data.c')
| -rw-r--r-- | src/data.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/src/data.c b/src/data.c index fd8cdd19aa2..2e7f3e017be 100644 --- a/src/data.c +++ b/src/data.c | |||
| @@ -3071,11 +3071,13 @@ usage: (logxor &rest INTS-OR-MARKERS) */) | |||
| 3071 | 3071 | ||
| 3072 | DEFUN ("logcount", Flogcount, Slogcount, 1, 1, 0, | 3072 | DEFUN ("logcount", Flogcount, Slogcount, 1, 1, 0, |
| 3073 | doc: /* Return population count of VALUE. | 3073 | doc: /* Return population count of VALUE. |
| 3074 | If VALUE is negative, the count is of its two's complement representation. */) | 3074 | This is the number of one bits in the two's complement representation |
| 3075 | of VALUE. If VALUE is negative, return the number of zero bits in the | ||
| 3076 | representation. */) | ||
| 3075 | (Lisp_Object value) | 3077 | (Lisp_Object value) |
| 3076 | { | 3078 | { |
| 3077 | CHECK_NUMBER (value); | 3079 | CHECK_NUMBER (value); |
| 3078 | EMACS_UINT v = XUINT (value); | 3080 | EMACS_INT v = XINT (value) < 0 ? -1 - XINT (value) : XINT (value); |
| 3079 | return make_number (EMACS_UINT_WIDTH <= UINT_WIDTH | 3081 | return make_number (EMACS_UINT_WIDTH <= UINT_WIDTH |
| 3080 | ? count_one_bits (v) | 3082 | ? count_one_bits (v) |
| 3081 | : EMACS_UINT_WIDTH <= ULONG_WIDTH | 3083 | : EMACS_UINT_WIDTH <= ULONG_WIDTH |