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
52
53
54
|
<h1 id="firstHeading" class="firstHeading">FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><math.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define FP_NORMAL /*implementation defined*/</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define FP_SUBNORMAL /*implementation defined*/</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define FP_ZERO /*implementation defined*/</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define FP_INFINITE /*implementation defined*/</pre>
</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define FP_NAN /*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>The <code>FP_NORMAL</code>, <code>FP_SUBNORMAL</code>, <code>FP_ZERO</code>, <code>FP_INFINITE</code>, <code>FP_NAN</code> macros each represent a distinct category of floating-point numbers. They all expand to an integer constant expression.</p>
<table class="t-dsc-begin"> <tr class="t-dsc-hitem"> <th> Constant </th> <th> Explanation </th>
</tr> <tr class="t-dsc"> <td> <code>FP_NORMAL</code> </td> <td> indicates that the value is <i>normal</i>, i.e. not an infinity, subnormal, not-a-number or zero </td>
</tr> <tr class="t-dsc"> <td> <code>FP_SUBNORMAL</code> </td> <td> indicates that the value is <a href="https://en.wikipedia.org/wiki/Subnormal_number" class="extiw" title="enwiki:Subnormal number"><i>subnormal</i></a> </td>
</tr> <tr class="t-dsc"> <td> <code>FP_ZERO</code> </td> <td> indicates that the value is positive or negative zero </td>
</tr> <tr class="t-dsc"> <td> <code>FP_INFINITE</code> </td> <td> indicates that the value is not representable by the underlying type (positive or negative infinity) </td>
</tr> <tr class="t-dsc"> <td> <code>FP_NAN</code> </td> <td> indicates that the value is not-a-number (NaN) </td>
</tr> </table> <h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h>
#include <math.h>
#include <float.h>
const char *show_classification(double x) {
switch(fpclassify(x)) {
case FP_INFINITE: return "Inf";
case FP_NAN: return "NaN";
case FP_NORMAL: return "normal";
case FP_SUBNORMAL: return "subnormal";
case FP_ZERO: return "zero";
default: return "unknown";
}
}
int main(void)
{
printf("1.0/0.0 is %s\n", show_classification(1/0.0));
printf("0.0/0.0 is %s\n", show_classification(0.0/0.0));
printf("DBL_MIN/2 is %s\n", show_classification(DBL_MIN/2));
printf("-0.0 is %s\n", show_classification(-0.0));
printf(" 1.0 is %s\n", show_classification(1.0));
}</pre></div> <p>Output:</p>
<div class="text source-text"><pre data-language="c">1.0/0.0 is Inf
0.0/0.0 is NaN
DBL_MIN/2 is subnormal
-0.0 is zero
1.0 is normal</pre></div> </div> <h3 id="References"> References</h3> <ul>
<li> C17 standard (ISO/IEC 9899:2018): </li>
<ul><li> 7.12/6 FP_NORMAL, ... (p: 169-170) </li></ul>
<li> C11 standard (ISO/IEC 9899:2011): </li>
<ul><li> 7.12/6 FP_NORMAL, ... (p: 232) </li></ul>
<li> C99 standard (ISO/IEC 9899:1999): </li>
<ul><li> 7.12/6 FP_NORMAL, ... (p: 213) </li></ul>
</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <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 colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/math/FP_categories" title="cpp/numeric/math/FP categories">C++ documentation</a></span> for <code>FP_categories</code> </td>
</tr> </table> <div class="_attribution">
<p class="_attribution-p">
© 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/FP_categories" class="_attribution-link">https://en.cppreference.com/w/c/numeric/math/FP_categories</a>
</p>
</div>
|