summaryrefslogtreecommitdiff
path: root/devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html
diff options
context:
space:
mode:
authorCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
committerCraig Jennings <c@cjennings.net>2024-04-07 13:41:34 -0500
commit754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch)
treef1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html
new repository
Diffstat (limited to 'devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html')
-rw-r--r--devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html87
1 files changed, 87 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html b/devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html
new file mode 100644
index 00000000..aa31da7a
--- /dev/null
+++ b/devdocs/c/numeric%2Ffenv%2Ffe_exceptions.html
@@ -0,0 +1,87 @@
+ <h1 id="firstHeading" class="firstHeading"><small>FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW, FE_ALL_EXCEPT</small></h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code>&lt;fenv.h&gt;</code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">#define FE_DIVBYZERO /*implementation defined power of 2*/</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 FE_INEXACT /*implementation defined power of 2*/</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 FE_INVALID /*implementation defined power of 2*/</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 FE_OVERFLOW /*implementation defined power of 2*/</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 FE_UNDERFLOW /*implementation defined power of 2*/</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 FE_ALL_EXCEPT FE_DIVBYZERO | FE_INEXACT | \
+ FE_INVALID | FE_OVERFLOW | \
+ FE_UNDERFLOW</pre>
+</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <p>All these macro constants (except <code>FE_ALL_EXCEPT</code>) expand to integer constant expressions that are distinct powers of 2, which uniquely identify all supported floating-point exceptions. Each macro is only defined if it is supported.</p>
+<p>The macro constant <code>FE_ALL_EXCEPT</code>, which expands to the bitwise OR of all other <code>FE_*</code>, is always defined and is zero if floating-point exceptions are not supported by the implementation.</p>
+<table class="t-dsc-begin"> <tr class="t-dsc-hitem"> <th> Constant </th> <th> Explanation </th>
+</tr> <tr class="t-dsc"> <td> <code>FE_DIVBYZERO</code> </td> <td> pole error occurred in an earlier floating-point operation </td>
+</tr> <tr class="t-dsc"> <td> <code>FE_INEXACT</code> </td> <td> inexact result: rounding was necessary to store the result of an earlier floating-point operation </td>
+</tr> <tr class="t-dsc"> <td> <code>FE_INVALID</code> </td> <td> domain error occurred in an earlier floating-point operation </td>
+</tr> <tr class="t-dsc"> <td> <code>FE_OVERFLOW</code> </td> <td> the result of an earlier floating-point operation was too large to be representable </td>
+</tr> <tr class="t-dsc"> <td> <code>FE_UNDERFLOW</code> </td> <td> the result of an earlier floating-point operation was subnormal with a loss of precision </td>
+</tr> <tr class="t-dsc"> <td> <code>FE_ALL_EXCEPT</code> </td> <td> bitwise OR of all supported floating-point exceptions </td>
+</tr> </table> <p>The implementation may define additional macro constants in <code>&lt;fenv.h&gt;</code> to identify additional floating-point exceptions. All such constants begin with <code>FE_</code> followed by at least one uppercase letter.</p>
+<p>See <a href="../math/math_errhandling" title="c/numeric/math/math errhandling">math_errhandling</a> for further details.</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;
+#include &lt;fenv.h&gt;
+
+#pragma STDC FENV_ACCESS ON
+void show_fe_exceptions(void)
+{
+ printf("exceptions raised:");
+ if(fetestexcept(FE_DIVBYZERO)) printf(" FE_DIVBYZERO");
+ if(fetestexcept(FE_INEXACT)) printf(" FE_INEXACT");
+ if(fetestexcept(FE_INVALID)) printf(" FE_INVALID");
+ if(fetestexcept(FE_OVERFLOW)) printf(" FE_OVERFLOW");
+ if(fetestexcept(FE_UNDERFLOW)) printf(" FE_UNDERFLOW");
+ feclearexcept(FE_ALL_EXCEPT);
+ printf("\n");
+}
+
+int main(void)
+{
+ printf("MATH_ERREXCEPT is %s\n",
+ math_errhandling &amp; MATH_ERREXCEPT ? "set" : "not set");
+
+ printf("0.0/0.0 = %f\n", 0.0/0.0);
+ show_fe_exceptions();
+
+ printf("1.0/0.0 = %f\n", 1.0/0.0);
+ show_fe_exceptions();
+
+ printf("1.0/10.0 = %f\n", 1.0/10.0);
+ show_fe_exceptions();
+
+ printf("sqrt(-1) = %f\n", sqrt(-1));
+ show_fe_exceptions();
+
+ printf("DBL_MAX*2.0 = %f\n", DBL_MAX*2.0);
+ show_fe_exceptions();
+
+ printf("nextafter(DBL_MIN/pow(2.0,52),0.0) = %.1f\n",
+ nextafter(DBL_MIN/pow(2.0,52),0.0));
+ show_fe_exceptions();
+}</pre></div> <p>Possible output:</p>
+<div class="text source-text"><pre data-language="c">MATH_ERREXCEPT is set
+0.0/0.0 = nan
+exceptions raised: FE_INVALID
+1.0/0.0 = inf
+exceptions raised: FE_DIVBYZERO
+1.0/10.0 = 0.100000
+exceptions raised: FE_INEXACT
+sqrt(-1) = -nan
+exceptions raised: FE_INVALID
+DBL_MAX*2.0 = inf
+exceptions raised: FE_INEXACT FE_OVERFLOW
+nextafter(DBL_MIN/pow(2.0,52),0.0) = 0.0
+exceptions raised: FE_INEXACT FE_UNDERFLOW</pre></div> </div> <h3 id="References"> References</h3> <ul>
+<li> C11 standard (ISO/IEC 9899:2011): </li>
+<ul><li> 7.6/6 Floating-point environment &lt;fenv.h&gt; (p: 207) </li></ul>
+<li> C99 standard (ISO/IEC 9899:1999): </li>
+<ul><li> 7.6/5 Floating-point environment &lt;fenv.h&gt; (p: 188) </li></ul>
+</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="../math/math_errhandling" title="c/numeric/math/math errhandling"> <span class="t-lines"><span>math_errhandling</span><span>MATH_ERRNO</span><span>MATH_ERREXCEPT</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> defines the error handling mechanism used by the common mathematical functions <br> <span class="t-mark">(macro constant)</span> </td>
+</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/fenv/FE_exceptions" title="cpp/numeric/fenv/FE exceptions">C++ documentation</a></span> for <span class=""><span>floating-point exception macros</span></span> </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/fenv/FE_exceptions" class="_attribution-link">https://en.cppreference.com/w/c/numeric/fenv/FE_exceptions</a>
+ </p>
+</div>