1
0
Fork 0
cl-sites/novaspec.org/cl/f_signum.html
2025-02-05 18:52:26 +01:00

355 lines
No EOL
7 KiB
HTML

<!DOCTYPE HTML>
<HTML LANG="en-us"
><HEAD
><TITLE
>signum | Common Lisp Nova Spec</TITLE
><META CHARSET="US-ASCII"
><LINK REL="canonical" HREF="f_signum.html"
><LINK REL="next" HREF="f_sqrt.html" TYPE="text/html" TITLE="sqrt, isqrt"
><LINK REL="prev" HREF="f_mod.html" TYPE="text/html" TITLE="mod, rem"
><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"
>&#8594; <A HREF="12_Numbers.html"
>12. Numbers</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="12_2_Numbers_Dictionary.html"
>12.2 Numbers Dictionary</A
></SPAN
> <SPAN CLASS="breadcrumb-item"
>&#8594; <A HREF="f_signum.html"
>signum</A
></SPAN
></DIV
><DIV CLASS="apropos"
><DIV CLASS="apropos-io"
><A HREF="f_mod.html" CLASS="prev"
>&#8592;</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_sqrt.html" CLASS="next"
>&#8594;</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="signum"
></SPAN
><B
>signum</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
>signum</B
> <SPAN CLASS="cmssi"
>number</SPAN
> <SPAN CLASS="arrow"
>&#8594;</SPAN
> <SPAN CLASS="cmssi"
>signed-prototype</SPAN
></P
></DD
><DT
><B
>Arguments and Values</B
></DT
><DD
><P CLASS="j"
><VAR CLASS="param"
>number</VAR
> &#8212; a <A HREF="26_1_Glossary.html#number"
><EM CLASS="term"
>number</EM
></A
>. </P
><P CLASS="j"
><VAR CLASS="param"
>signed-prototype</VAR
> &#8212; a <A HREF="26_1_Glossary.html#number"
><EM CLASS="term"
>number</EM
></A
>.</P
></DD
><DT
><B
>Description</B
></DT
><DD
><P CLASS="j"
><A HREF="f_signum.html" CLASS="funref"
><B
>signum</B
></A
> determines a numerical value that indicates whether <VAR CLASS="param"
>number</VAR
> is negative, zero, or positive. </P
><P CLASS="j"
>For a <A HREF="26_1_Glossary.html#rational"
><EM CLASS="term"
>rational</EM
></A
>, <A HREF="f_signum.html" CLASS="funref"
><B
>signum</B
></A
> returns one of <CODE CLASS="f"
>-1</CODE
>, <CODE CLASS="f"
>0</CODE
>, or <CODE CLASS="f"
>1</CODE
> according to whether <VAR CLASS="param"
>number</VAR
> is negative, zero, or positive. For a <A HREF="26_1_Glossary.html#float"
><EM CLASS="term"
>float</EM
></A
>, the result is a <A HREF="26_1_Glossary.html#float"
><EM CLASS="term"
>float</EM
></A
> of the same format whose value is minus one, zero, or one. For a <A HREF="26_1_Glossary.html#complex"
><EM CLASS="term"
>complex</EM
></A
> number <CODE CLASS="f"
>z</CODE
>, <CODE CLASS="f"
>(signum <I CLASS="i"
><I
>z</I
></I
>)</CODE
> is a complex number of the same phase but with unit magnitude, unless <CODE CLASS="f"
>z</CODE
> is a complex zero, in which case the result is <CODE CLASS="f"
>z</CODE
>. </P
><P CLASS="j"
>For <A HREF="26_1_Glossary.html#rational"
><EM CLASS="term"
>rational</EM
></A
> <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
>, <A HREF="f_signum.html" CLASS="funref"
><B
>signum</B
></A
> is a rational function, but it may be irrational for <A HREF="26_1_Glossary.html#complex"
><EM CLASS="term"
>complex</EM
></A
> <A HREF="26_1_Glossary.html#argument"
><EM CLASS="term"
>arguments</EM
></A
>. </P
><P CLASS="j"
>If <VAR CLASS="param"
>number</VAR
> is a <A HREF="26_1_Glossary.html#float"
><EM CLASS="term"
>float</EM
></A
>, the result is a <A HREF="26_1_Glossary.html#float"
><EM CLASS="term"
>float</EM
></A
>. If <VAR CLASS="param"
>number</VAR
> is a <A HREF="26_1_Glossary.html#rational"
><EM CLASS="term"
>rational</EM
></A
>, the result is a <A HREF="26_1_Glossary.html#rational"
><EM CLASS="term"
>rational</EM
></A
>. If <VAR CLASS="param"
>number</VAR
> is a <A HREF="26_1_Glossary.html#complex_float"
><EM CLASS="term"
>complex float</EM
></A
>, the result is a <A HREF="26_1_Glossary.html#complex_float"
><EM CLASS="term"
>complex float</EM
></A
>. If <VAR CLASS="param"
>number</VAR
> is a <A HREF="26_1_Glossary.html#complex_rational"
><EM CLASS="term"
>complex rational</EM
></A
>, the result is a <A HREF="26_1_Glossary.html#complex"
><EM CLASS="term"
>complex</EM
></A
>, but it is <A HREF="26_1_Glossary.html#implementation-dependent"
><EM CLASS="term"
>implementation-dependent</EM
></A
> whether that result is a <A HREF="26_1_Glossary.html#complex_rational"
><EM CLASS="term"
>complex rational</EM
></A
> or a <A HREF="26_1_Glossary.html#complex_float"
><EM CLASS="term"
>complex float</EM
></A
>.</P
></DD
><DT
><B
>Examples</B
></DT
><DD
><PRE CLASS="screen"
>(signum 0) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 0
(signum 99) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(signum 4/5) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 1
(signum -99/100) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> -1
(signum 0.0) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> 0.0
(signum #c(0 33)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #C(0.0 1.0)
(signum #c(7.5 10.0)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #C(0.6 0.8)
(signum #c(0.0 -14.7)) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> #C(0.0 -1.0)
(eql (signum -0.0) -0.0) <SPAN CLASS="cmsy"
><SPAN CLASS="arrow"
>&#8594;</SPAN
></SPAN
> <A HREF="26_1_Glossary.html#true"
><EM CLASS="term"
>true</EM
></A
></PRE
></DD
><DT
><B
>See Also</B
></DT
><DD
><P CLASS="j"
><A HREF="12_1_Number_Concepts.html#sec_12_1_3_3" CLASS="secref"
><SPAN CLASS="cmr"
>Section</SPAN
> <SPAN CLASS="cmr"
>12.1.3.3</SPAN
> <SPAN CLASS="cmr"
>(Rule</SPAN
> <SPAN CLASS="cmr"
>of</SPAN
> <SPAN CLASS="cmr"
>Float</SPAN
> <SPAN CLASS="cmr"
>Substitutability)</SPAN
></A
></P
></DD
><DT
><B
>Notes</B
></DT
><DD
><PRE CLASS="screen"
>(signum x) <SPAN CLASS="cmsy"
><SPAN STYLE="font-size:16px;vertical-align:-2px"
>&#8801;</SPAN
></SPAN
> (if (zerop x) x (/ x (abs x)))</PRE
></DD
></DL
></DIV
></DIV
><DIV CLASS="footer"
><DIV CLASS="btmnav"
><A HREF="f_mod.html" CLASS="prev"
>&#8592;</A
><A HREF="f_sqrt.html" CLASS="next"
>&#8594;</A
></DIV
><DIV CLASS="trail"
>Conversion to HTML copyright 2023 by Gilbert Baumann</DIV
></DIV
></DIV
><SCRIPT
>domReady();</SCRIPT
></BODY
></HTML
>