summaryrefslogtreecommitdiff
path: root/doc/lispref/numbers.texi
diff options
context:
space:
mode:
authorMark Oteiza <mvoteiza@udel.edu>2017-09-30 14:14:12 -0400
committerMark Oteiza <mvoteiza@udel.edu>2017-09-30 14:16:18 -0400
commit185f33340680d918a95ff704a8f7e2d9e1a6f0ca (patch)
treeaf80fe1f744c467325c54a0361d6f1309bbe2855 /doc/lispref/numbers.texi
parent20a09de953f437109a098fa8c4d380663d921481 (diff)
downloademacs-185f33340680d918a95ff704a8f7e2d9e1a6f0ca.tar.gz
Add logcount (Bug#22689)
* doc/lispref/numbers.texi (Bitwise Operations): Add documentation. * etc/NEWS: Mention. * src/data.c (logcount32, logcount64): New functions. (logcount): New Lisp function. (syms_of_data): Declare it. * test/src/data-tests.el (data-tests-popcnt, data-tests-logcount): New test.
Diffstat (limited to 'doc/lispref/numbers.texi')
-rw-r--r--doc/lispref/numbers.texi13
1 files changed, 13 insertions, 0 deletions
diff --git a/doc/lispref/numbers.texi b/doc/lispref/numbers.texi
index 3fdc94169bd..5058063af4d 100644
--- a/doc/lispref/numbers.texi
+++ b/doc/lispref/numbers.texi
@@ -1107,6 +1107,19 @@ bit is one in the result if, and only if, the @var{n}th bit is zero in
@end example
@end defun
+@cindex popcount
+@cindex Hamming weight
+@cindex counting set bits
+@defun logcount integer
+This function returns the @dfn{Hamming weight} of @var{integer}: the
+number of ones in the binary representation of @var{integer}.
+
+@example
+(logcount 42) ; 42 = #b101010
+ @result{} 3
+@end example
+@end defun
+
@node Math Functions
@section Standard Mathematical Functions
@cindex transcendental functions