summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Fmath%2Fisnan.html
blob: f9b432de322068f4b07abbc78afec44a26b84a7d (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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
    <h1 id="firstHeading" class="firstHeading">isnan</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 isnan(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 a not-a-number (NaN) value. The macro returns an integral value.</p>
<p><code><a href="../../types/limits/flt_eval_method" title="c/types/limits/FLT EVAL METHOD">FLT_EVAL_METHOD</a></code> is ignored: even if the argument is evaluated with more range and precision than its type, it is first converted to its semantic type, and the classification is based on that (this matters if the evaluation type supports NaNs, while the semantic type does not).</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 a NaN, <code>​0​</code> otherwise.</p>
<h3 id="Notes"> Notes</h3> <p>There are many different NaN values with different sign bits and payloads, see <code><a href="nan" title="c/numeric/math/nan">nan</a></code>.</p>
<p>NaN values never compare equal to themselves or to other NaN values. Copying a NaN may change its bit pattern.</p>
<p>Another way to test if a floating-point value is NaN is to compare it with itself: <code>bool is_nan(double x) { return x != x; }</code></p>
<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include &lt;stdio.h&gt;
#include &lt;math.h&gt;
#include &lt;float.h&gt;
 
int main(void)
{
    printf("isnan(NAN)         = %d\n", isnan(NAN));
    printf("isnan(INFINITY)    = %d\n", isnan(INFINITY));
    printf("isnan(0.0)         = %d\n", isnan(0.0));
    printf("isnan(DBL_MIN/2.0) = %d\n", isnan(DBL_MIN/2.0));
    printf("isnan(0.0 / 0.0)   = %d\n", isnan(0.0/0.0));
    printf("isnan(Inf - Inf)   = %d\n", isnan(INFINITY - INFINITY));
}</pre></div> <p>Possible output:</p>
<div class="text source-text"><pre data-language="c">isnan(NAN)         = 1
isnan(INFINITY)    = 0
isnan(0.0)         = 0
isnan(DBL_MIN/2.0) = 0
isnan(0.0 / 0.0)   = 1
isnan(Inf - Inf)   = 1</pre></div> </div> <h3 id="References"> References</h3>  <ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.12.3.4 The isnan macro (p: 236-237) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.12.3.4 The isnan macro (p: 217) </li></ul>
</ul>      <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="nan" title="c/numeric/math/nan"> <span class="t-lines"><span>nan</span><span>nanf</span><span>nanl</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> returns a NaN (not-a-number) <br> <span class="t-mark">(function)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="fpclassify" title="c/numeric/math/fpclassify"> <span class="t-lines"><span>fpclassify</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> classifies the given floating-point value <br> <span class="t-mark">(function macro)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="isfinite" title="c/numeric/math/isfinite"> <span class="t-lines"><span>isfinite</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> checks if the given number has finite value <br> <span class="t-mark">(function macro)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="isinf" title="c/numeric/math/isinf"> <span class="t-lines"><span>isinf</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> checks if the given number is infinite <br> <span class="t-mark">(function macro)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="isnormal" title="c/numeric/math/isnormal"> <span class="t-lines"><span>isnormal</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> checks if the given number is normal <br> <span class="t-mark">(function macro)</span>  </td>
</tr> <tr class="t-dsc"> <td> <div><a href="isunordered" title="c/numeric/math/isunordered"> <span class="t-lines"><span>isunordered</span></span></a></div>
<div><span class="t-lines"><span><span class="t-mark-rev t-since-c99">(C99)</span></span></span></div> </td> <td> checks if two floating-point values are unordered <br> <span class="t-mark">(function macro)</span>  </td>
</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/isnan" title="cpp/numeric/math/isnan">C++ documentation</a></span> for <code>isnan</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/isnan" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/isnan</a>
  </p>
</div>