summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fmath%2Fsignbit.html
blob: dc7e42da59a47949c3ac65b7eb8620571f1a1ac4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
    <h1 id="firstHeading" class="firstHeading">signbit</h1>            <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;math.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define signbit( arg ) /* implementation defined */</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr>  </table> <p>Determines if the given floating point number <code>arg</code> is negative. The macro returns an integral value.</p>
<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> arg </td> <td> - </td> <td> floating point value </td>
</tr>
</table> <h3 id="Return_value"> Return value</h3> <p>Nonzero integral value if <code>arg</code> is negative, <code>​0​</code> otherwise.</p>
<h3 id="Notes"> Notes</h3> <p>This macro detects the sign bit of zeroes, infinities, and NaNs. Along with <code><a href="copysign" title="c/numeric/math/copysign">copysign</a></code>, this macro is one of the only two portable ways to examine the sign of a NaN.</p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;math.h&gt;
#include &lt;stdio.h&gt;
 
int main(void)
{
    printf("signbit(+0.0) = %d\n", signbit(+0.0));
    printf("signbit(-0.0) = %d\n", signbit(-0.0));
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">signbit(+0.0) = 0
signbit(-0.0) = 128</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C23 standard (ISO/IEC 9899:2023): </li>
<ul><li> 7.12.3.6 The signbit macro (p: TBD) </li></ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.12.3.6 The signbit macro (p: TBD) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.12.3.6 The signbit macro (p: 237) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.12.3.6 The signbit macro (p: 218) </li></ul>
</ul>               <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="fabs" title="c/numeric/math/fabs"> <span class="t-lines"><span>fabs</span><span>fabsf</span><span>fabsl</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> computes absolute value of a floating-point value (\(\small{|x|}\)|x|) <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="copysign" title="c/numeric/math/copysign"> <span class="t-lines"><span>copysign</span><span>copysignf</span><span>copysignl</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> produces a value with the magnitude of a given value and the sign of another given value <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/signbit" title="cpp/numeric/math/signbit">C++ documentation</a></span> for <code>signbit</code> </td>
</tr> </table>           <div class="_attribution">
  <p class="_attribution-p">
    &copy; cppreference.com<br>Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.<br>
    <a href="https://en.cppreference.com/w/c/numeric/math/signbit" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/signbit</a>
  </p>
</div>