Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

fpclassify.html 9.1KB

3 år sedan
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  4. <head>
  5. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  6. <title>fpclassify (LIBM)</title>
  7. <meta name="description" content="fpclassify (LIBM)">
  8. <meta name="keywords" content="fpclassify (LIBM)">
  9. <meta name="resource-type" content="document">
  10. <meta name="distribution" content="global">
  11. <meta name="Generator" content="makeinfo">
  12. <link href="index.html#Top" rel="start" title="Top">
  13. <link href="Document-Index.html#Document-Index" rel="index" title="Document Index">
  14. <link href="Document-Index.html#SEC_Contents" rel="contents" title="Table of Contents">
  15. <link href="Math.html#Math" rel="up" title="Math">
  16. <link href="ldexp.html#ldexp" rel="next" title="ldexp">
  17. <link href="isgreater.html#isgreater" rel="prev" title="isgreater">
  18. <style type="text/css">
  19. <!--
  20. a.summary-letter {text-decoration: none}
  21. blockquote.indentedblock {margin-right: 0em}
  22. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  23. blockquote.smallquotation {font-size: smaller}
  24. div.display {margin-left: 3.2em}
  25. div.example {margin-left: 3.2em}
  26. div.lisp {margin-left: 3.2em}
  27. div.smalldisplay {margin-left: 3.2em}
  28. div.smallexample {margin-left: 3.2em}
  29. div.smalllisp {margin-left: 3.2em}
  30. kbd {font-style: oblique}
  31. pre.display {font-family: inherit}
  32. pre.format {font-family: inherit}
  33. pre.menu-comment {font-family: serif}
  34. pre.menu-preformatted {font-family: serif}
  35. pre.smalldisplay {font-family: inherit; font-size: smaller}
  36. pre.smallexample {font-size: smaller}
  37. pre.smallformat {font-family: inherit; font-size: smaller}
  38. pre.smalllisp {font-size: smaller}
  39. span.nolinebreak {white-space: nowrap}
  40. span.roman {font-family: initial; font-weight: normal}
  41. span.sansserif {font-family: sans-serif; font-weight: normal}
  42. ul.no-bullet {list-style: none}
  43. -->
  44. </style>
  45. </head>
  46. <body lang="en">
  47. <a name="fpclassify"></a>
  48. <div class="header">
  49. <p>
  50. Next: <a href="ldexp.html#ldexp" accesskey="n" rel="next">ldexp</a>, Previous: <a href="isgreater.html#isgreater" accesskey="p" rel="prev">isgreater</a>, Up: <a href="Math.html#Math" accesskey="u" rel="up">Math</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  51. </div>
  52. <hr>
  53. <a name="fpclassify_002c-isfinite_002c-isinf_002c-isnan_002c-and-isnormal_002d_002d_002dfloating_002dpoint-classification-macros_003b-finite_002c-finitef_002c-isinf_002c-isinff_002c-isnan_002c-isnanf_002d_002d_002dtest-for-exceptional-numbers"></a>
  54. <h3 class="section">1.32 <code>fpclassify</code>, <code>isfinite</code>, <code>isinf</code>, <code>isnan</code>, and <code>isnormal</code>&mdash;floating-point classification macros; <code>finite</code>, <code>finitef</code>, <code>isinf</code>, <code>isinff</code>, <code>isnan</code>, <code>isnanf</code>&mdash;test for exceptional numbers</h3>
  55. <a name="index-fpclassify"></a>
  56. <a name="index-isfinite"></a>
  57. <a name="index-isinf"></a>
  58. <a name="index-isnan"></a>
  59. <a name="index-isnormal"></a>
  60. <a name="index-isnan-1"></a>
  61. <a name="index-isinf-1"></a>
  62. <a name="index-finite"></a>
  63. <a name="index-isnanf"></a>
  64. <a name="index-isinff"></a>
  65. <a name="index-finitef"></a>
  66. <p><strong>Synopsis</strong>
  67. </p><div class="example">
  68. <pre class="example">[C99 standard macros:]
  69. #include &lt;math.h&gt;
  70. int fpclassify(real-floating <var>x</var>);
  71. int isfinite(real-floating <var>x</var>);
  72. int isinf(real-floating <var>x</var>);
  73. int isnan(real-floating <var>x</var>);
  74. int isnormal(real-floating <var>x</var>);
  75. [Archaic SUSv2 functions:]
  76. #include &lt;math.h&gt;
  77. int isnan(double <var>arg</var>);
  78. int isinf(double <var>arg</var>);
  79. int finite(double <var>arg</var>);
  80. int isnanf(float <var>arg</var>);
  81. int isinff(float <var>arg</var>);
  82. int finitef(float <var>arg</var>);
  83. </pre></div>
  84. <p><strong>Description</strong><br>
  85. <code>fpclassify</code>, <code>isfinite</code>, <code>isinf</code>, <code>isnan</code>, and <code>isnormal</code> are macros
  86. defined for use in classifying floating-point numbers. This is a help because
  87. of special &quot;values&quot; like NaN and infinities. In the synopses shown,
  88. &quot;real-floating&quot; indicates that the argument is an expression of real floating
  89. type. These function-like macros are C99 and POSIX-compliant, and should be
  90. used instead of the now-archaic SUSv2 functions.
  91. </p>
  92. <p>The <code>fpclassify</code> macro classifies its argument value as NaN, infinite, normal,
  93. subnormal, zero, or into another implementation-defined category. First, an
  94. argument represented in a format wider than its semantic type is converted to
  95. its semantic type. Then classification is based on the type of the argument.
  96. The <code>fpclassify</code> macro returns the value of the number classification macro
  97. appropriate to the value of its argument:
  98. </p>
  99. <dl compact="compact">
  100. <dt><code>FP_INFINITE</code></dt>
  101. <dd><p><var>x</var> is either plus or minus infinity;
  102. </p></dd>
  103. <dt><code>FP_NAN</code></dt>
  104. <dd><p><var>x</var> is &quot;Not A Number&quot; (plus or minus);
  105. </p></dd>
  106. <dt><code>FP_NORMAL</code></dt>
  107. <dd><p><var>x</var> is a &quot;normal&quot; number (i.e. is none of the other special forms);
  108. </p></dd>
  109. <dt><code>FP_SUBNORMAL</code></dt>
  110. <dd><p><var>x</var> is too small be stored as a regular normalized number (i.e. loss of precision is likely); or
  111. </p></dd>
  112. <dt><code>FP_ZERO</code></dt>
  113. <dd><p><var>x</var> is 0 (either plus or minus).
  114. </p></dd>
  115. </dl>
  116. <p>The &quot;<code>is</code>&quot; set of macros provide a useful set of shorthand ways for
  117. classifying floating-point numbers, providing the following equivalent
  118. relations:
  119. </p>
  120. <dl compact="compact">
  121. <dt><code><code>isfinite</code>(<var>x</var>)</code></dt>
  122. <dd><p>returns non-zero if <var>x</var> is finite. (It is equivalent to
  123. (<code>fpclassify</code>(<var>x</var>) != FP_INFINITE &amp;&amp; <code>fpclassify</code>(<var>x</var>) != FP_NAN).)
  124. </p>
  125. </dd>
  126. <dt><code><code>isinf</code>(<var>x</var>)</code></dt>
  127. <dd><p>returns non-zero if <var>x</var> is infinite. (It is equivalent to
  128. (<code>fpclassify</code>(<var>x</var>) == FP_INFINITE).)
  129. </p>
  130. </dd>
  131. <dt><code><code>isnan</code>(<var>x</var>)</code></dt>
  132. <dd><p>returns non-zero if <var>x</var> is NaN. (It is equivalent to
  133. (<code>fpclassify</code>(<var>x</var>) == FP_NAN).)
  134. </p>
  135. </dd>
  136. <dt><code><code>isnormal</code>(<var>x</var>)</code></dt>
  137. <dd><p>returns non-zero if <var>x</var> is normal. (It is equivalent to
  138. (<code>fpclassify</code>(<var>x</var>) == FP_NORMAL).)
  139. </p></dd>
  140. </dl>
  141. <p>The archaic SUSv2 functions provide information on the floating-point
  142. argument supplied.
  143. </p>
  144. <p>There are five major number formats (&quot;exponent&quot; referring to the
  145. biased exponent in the binary-encoded number):
  146. </p><dl compact="compact">
  147. <dt><code>zero</code></dt>
  148. <dd><p>A number which contains all zero bits, excluding the sign bit.
  149. </p></dd>
  150. <dt><code>subnormal</code></dt>
  151. <dd><p>A number with a zero exponent but a nonzero fraction.
  152. </p></dd>
  153. <dt><code>normal</code></dt>
  154. <dd><p>A number with an exponent and a fraction.
  155. </p></dd>
  156. <dt><code>infinity</code></dt>
  157. <dd><p>A number with an all 1&rsquo;s exponent and a zero fraction.
  158. </p></dd>
  159. <dt><code>NAN</code></dt>
  160. <dd><p>A number with an all 1&rsquo;s exponent and a nonzero fraction.
  161. </p>
  162. </dd>
  163. </dl>
  164. <p><code>isnan</code> returns 1 if the argument is a nan. <code>isinf</code>
  165. returns 1 if the argument is infinity. <code>finite</code> returns 1 if the
  166. argument is zero, subnormal or normal.
  167. The <code>isnanf</code>, <code>isinff</code> and <code>finitef</code> functions perform the same
  168. operations as their <code>isnan</code>, <code>isinf</code> and <code>finite</code>
  169. counterparts, but on single-precision floating-point numbers.
  170. </p>
  171. <p>It should be noted that the C99 standard dictates that <code>isnan</code>
  172. and <code>isinf</code> are macros that operate on multiple types of
  173. floating-point. The SUSv2 standard declares <code>isnan</code> as
  174. a function taking double. Newlib has decided to declare
  175. them both as functions and as macros in math.h to
  176. maintain backward compatibility.
  177. </p>
  178. <br>
  179. <p><strong>Returns</strong><br>
  180. The fpclassify macro returns the value corresponding to the appropriate FP_ macro.<br>
  181. The isfinite macro returns nonzero if <var>x</var> is finite, else 0.<br>
  182. The isinf macro returns nonzero if <var>x</var> is infinite, else 0.<br>
  183. The isnan macro returns nonzero if <var>x</var> is an NaN, else 0.<br>
  184. The isnormal macro returns nonzero if <var>x</var> has a normal value, else 0.
  185. </p>
  186. <br>
  187. <p><strong>Portability</strong><br>
  188. math.h macros are C99, POSIX.1-2001.
  189. </p>
  190. <p>The functions originate from BSD; isnan was listed in the X/Open
  191. Portability Guide and Single Unix Specification, but was dropped when
  192. the macro was standardized in POSIX.1-2001.
  193. </p>
  194. <br>
  195. <hr>
  196. <div class="header">
  197. <p>
  198. Next: <a href="ldexp.html#ldexp" accesskey="n" rel="next">ldexp</a>, Previous: <a href="isgreater.html#isgreater" accesskey="p" rel="prev">isgreater</a>, Up: <a href="Math.html#Math" accesskey="u" rel="up">Math</a> &nbsp; [<a href="Document-Index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="Document-Index.html#Document-Index" title="Index" rel="index">Index</a>]</p>
  199. </div>
  200. </body>
  201. </html>