262 lines
5.4 KiB
HTML
262 lines
5.4 KiB
HTML
|
<!DOCTYPE HTML>
|
||
|
<HTML LANG="en-us"
|
||
|
><HEAD
|
||
|
><TITLE
|
||
|
>logcount | Common Lisp Nova Spec</TITLE
|
||
|
><META CHARSET="US-ASCII"
|
||
|
><LINK REL="canonical" HREF="f_logcount.html"
|
||
|
><LINK REL="next" HREF="f_logtest.html" TYPE="text/html" TITLE="logtest"
|
||
|
><LINK REL="prev" HREF="f_logbitp.html" TYPE="text/html" TITLE="logbitp"
|
||
|
><LINK REL="up" HREF="12_2_Numbers_Dictionary.html" TYPE="text/html" TITLE="12.2 Numbers Dictionary"
|
||
|
><LINK REL="start" HREF="index.html" TYPE="text/html" TITLE="Common Lisp Nova Spec"
|
||
|
><META NAME="VIEWPORT" CONTENT="width=device-width, initial-scale=1.0"
|
||
|
><LINK REL="STYLESHEET" HREF="dpans.css%3F3909942064.css"
|
||
|
><SCRIPT SRC="dpans.js%3F3909942064"
|
||
|
></SCRIPT
|
||
|
><SCRIPT SRC="apropos.js%3F3909942064"
|
||
|
></SCRIPT
|
||
|
></HEAD
|
||
|
><BODY
|
||
|
><DIV
|
||
|
><DIV CLASS="topnav"
|
||
|
><DIV CLASS="breadcrumb"
|
||
|
><SPAN CLASS="breadcrumb-item"
|
||
|
><A HREF="index.html"
|
||
|
>Common Lisp Nova Spec</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="12_Numbers.html"
|
||
|
>12. Numbers</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="12_2_Numbers_Dictionary.html"
|
||
|
>12.2 Numbers Dictionary</A
|
||
|
></SPAN
|
||
|
> <SPAN CLASS="breadcrumb-item"
|
||
|
>→ <A HREF="f_logcount.html"
|
||
|
>logcount</A
|
||
|
></SPAN
|
||
|
></DIV
|
||
|
><DIV CLASS="apropos"
|
||
|
><DIV CLASS="apropos-io"
|
||
|
><A HREF="f_logbitp.html" CLASS="prev"
|
||
|
>←</A
|
||
|
><SPAN ID="apropos-label"
|
||
|
>Apropos </SPAN
|
||
|
><INPUT ID="apropos" AUTOFOCUS="AUTOFOCUS" PLACEHOLDER="Type here to search" ONINPUT="aproposInput(this);" ONKEYUP="aproposKeyup(event);" ONCHANGE="aproposChange(this);" ONFOCUS="aproposFocus(this);" ONFOCUSOUT="aproposFocusout(this);"
|
||
|
><A HREF="f_logtest.html" CLASS="next"
|
||
|
>→</A
|
||
|
></DIV
|
||
|
><DIV ID="apropos-res"
|
||
|
></DIV
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><DIV CLASS="matter"
|
||
|
><DIV CLASS="com"
|
||
|
><DIV CLASS="begincom"
|
||
|
><HR
|
||
|
><TABLE WIDTH="100%" CELLSPACING="0" CELLPADDING="0"
|
||
|
><TR
|
||
|
><TD ALIGN="LEFT" VALIGN="BASELINE" WIDTH="100%" CLASS="name"
|
||
|
><SPAN CLASS="idx" DATA-KIND="idxref" DATA-TERM="logcount"
|
||
|
></SPAN
|
||
|
><B
|
||
|
>logcount</B
|
||
|
></TD
|
||
|
><TD ALIGN="RIGHT" VALIGN="BASELINE" WIDTH="0" NOWRAP="NOWRAP" CLASS="ftype"
|
||
|
><I
|
||
|
>Function</I
|
||
|
></TD
|
||
|
></TR
|
||
|
></TABLE
|
||
|
><HR
|
||
|
></DIV
|
||
|
><UL CLASS="subtoc"
|
||
|
></UL
|
||
|
><DL
|
||
|
><DT
|
||
|
><B
|
||
|
>Syntax</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
><B
|
||
|
>logcount</B
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>integer</SPAN
|
||
|
> <SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
> <SPAN CLASS="cmssi"
|
||
|
>number-of-on-bits</SPAN
|
||
|
></P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Arguments and Values</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>integer</VAR
|
||
|
> — an <A HREF="26_1_Glossary.html#integer"
|
||
|
><EM CLASS="term"
|
||
|
>integer</EM
|
||
|
></A
|
||
|
>. </P
|
||
|
><P CLASS="j"
|
||
|
><VAR CLASS="param"
|
||
|
>number-of-on-bits</VAR
|
||
|
> — a non-negative <A HREF="26_1_Glossary.html#integer"
|
||
|
><EM CLASS="term"
|
||
|
>integer</EM
|
||
|
></A
|
||
|
>.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Description</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Computes and returns the number of bits in the two’s-complement binary representation of <VAR CLASS="param"
|
||
|
>integer</VAR
|
||
|
> that are ‘on’ or ‘set’. If <VAR CLASS="param"
|
||
|
>integer</VAR
|
||
|
> is negative, the <CODE CLASS="f"
|
||
|
>0</CODE
|
||
|
> bits are counted; otherwise, the <CODE CLASS="f"
|
||
|
>1</CODE
|
||
|
> bits are counted.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Examples</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><PRE CLASS="screen"
|
||
|
>(logcount 0) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 0
|
||
|
(logcount -1) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 0
|
||
|
(logcount 7) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 3
|
||
|
(logcount 13) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 3 ;Two's-complement binary: ...0001101
|
||
|
(logcount -13) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 2 ;Two's-complement binary: ...1110011
|
||
|
(logcount 30) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 4 ;Two's-complement binary: ...0011110
|
||
|
(logcount -30) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 4 ;Two's-complement binary: ...1100010
|
||
|
(logcount (expt 2 100)) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 1
|
||
|
(logcount (- (expt 2 100))) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 100
|
||
|
(logcount (- (1+ (expt 2 100)))) <SPAN CLASS="cmsy"
|
||
|
><SPAN CLASS="arrow"
|
||
|
>→</SPAN
|
||
|
></SPAN
|
||
|
> 1</PRE
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Exceptional Situations</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Should signal <A HREF="t_type-error.html" CLASS="typeref"
|
||
|
><B
|
||
|
>type-error</B
|
||
|
></A
|
||
|
> if its argument is not an <A HREF="26_1_Glossary.html#integer"
|
||
|
><EM CLASS="term"
|
||
|
>integer</EM
|
||
|
></A
|
||
|
>.</P
|
||
|
></DD
|
||
|
><DT
|
||
|
><B
|
||
|
>Notes</B
|
||
|
></DT
|
||
|
><DD
|
||
|
><P CLASS="j"
|
||
|
>Even if the <A HREF="26_1_Glossary.html#implementation"
|
||
|
><EM CLASS="term"
|
||
|
>implementation</EM
|
||
|
></A
|
||
|
> does not represent <A HREF="26_1_Glossary.html#integer"
|
||
|
><EM CLASS="term"
|
||
|
>integers</EM
|
||
|
></A
|
||
|
> internally in two’s complement binary, <A HREF="f_logcount.html" CLASS="funref"
|
||
|
><B
|
||
|
>logcount</B
|
||
|
></A
|
||
|
> behaves as if it did. </P
|
||
|
><P CLASS="j"
|
||
|
>The following identity always holds:</P
|
||
|
><PRE CLASS="screen"
|
||
|
> (logcount <VAR CLASS="param"
|
||
|
>x</VAR
|
||
|
>)
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN STYLE="font-size:16px;vertical-align:-2px"
|
||
|
>≡</SPAN
|
||
|
></SPAN
|
||
|
> (logcount (- (+ <VAR CLASS="param"
|
||
|
>x</VAR
|
||
|
> 1)))
|
||
|
<SPAN CLASS="cmsy"
|
||
|
><SPAN STYLE="font-size:16px;vertical-align:-2px"
|
||
|
>≡</SPAN
|
||
|
></SPAN
|
||
|
> (logcount (lognot <VAR CLASS="param"
|
||
|
>x</VAR
|
||
|
>))</PRE
|
||
|
></DD
|
||
|
></DL
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><DIV CLASS="footer"
|
||
|
><DIV CLASS="btmnav"
|
||
|
><A HREF="f_logbitp.html" CLASS="prev"
|
||
|
>←</A
|
||
|
><A HREF="f_logtest.html" CLASS="next"
|
||
|
>→</A
|
||
|
></DIV
|
||
|
><DIV CLASS="trail"
|
||
|
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
|
||
|
></DIV
|
||
|
></DIV
|
||
|
><SCRIPT
|
||
|
>domReady();</SCRIPT
|
||
|
></BODY
|
||
|
></HTML
|
||
|
>
|