diff options
| author | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
|---|---|---|
| committer | Craig Jennings <c@cjennings.net> | 2024-04-07 13:41:34 -0500 |
| commit | 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 (patch) | |
| tree | f1190704f78f04a2b0b4c977d20fe96a828377f1 /devdocs/c/numeric%2Ffenv%2Ffeupdateenv.html | |
new repository
Diffstat (limited to 'devdocs/c/numeric%2Ffenv%2Ffeupdateenv.html')
| -rw-r--r-- | devdocs/c/numeric%2Ffenv%2Ffeupdateenv.html | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Ffenv%2Ffeupdateenv.html b/devdocs/c/numeric%2Ffenv%2Ffeupdateenv.html new file mode 100644 index 00000000..e05e65a3 --- /dev/null +++ b/devdocs/c/numeric%2Ffenv%2Ffeupdateenv.html @@ -0,0 +1,74 @@ + <h1 id="firstHeading" class="firstHeading">feupdateenv</h1> <table class="t-dcl-begin"> <tr class="t-dsc-header"> <th> Defined in header <code><fenv.h></code> </th> <th> </th> <th> </th> </tr> <tr class="t-dcl t-since-c99"> <td> <pre data-language="c">int feupdateenv( const fenv_t* envp );</pre> +</td> <td class="t-dcl-nopad"> </td> <td> <span class="t-mark-rev t-since-c99">(since C99)</span> </td> </tr> </table> <p>First, remembers the currently raised floating-point exceptions, then restores the floating-point environment from the object pointed to by <code>envp</code> (similar to <code><a href="feenv" title="c/numeric/fenv/feenv">fesetenv</a></code>), then raises the floating-point exceptions that were saved.</p> +<p>This function may be used to end the non-stop mode established by an earlier call to <code><a href="feholdexcept" title="c/numeric/fenv/feholdexcept">feholdexcept</a></code>.</p> +<h3 id="Parameters"> Parameters</h3> <table class="t-par-begin"> <tr class="t-par"> <td> envp </td> <td> - </td> <td> pointer to the object of type <code>fenv_t</code> set by an earlier call to <code><a href="feholdexcept" title="c/numeric/fenv/feholdexcept">feholdexcept</a></code> or <code>fegetenv</code> or equal to <code><a href="fe_dfl_env" title="c/numeric/fenv/FE DFL ENV">FE_DFL_ENV</a></code> </td> +</tr> +</table> <h3 id="Return_value"> Return value</h3> <p><code>0</code> on success, non-zero otherwise.</p> +<h3 id="Example"> Example</h3> <div class="t-example"> <div class="c source-c"><pre data-language="c">#include <stdio.h> +#include <fenv.h> +#include <float.h> + +#pragma STDC FENV_ACCESS ON + +void show_fe_exceptions(void) +{ + printf("current 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"); + if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none"); + printf("\n"); +} + +double x2 (double x) /* times two */ +{ + fenv_t curr_excepts; + + /* Save and clear current f-p environment. */ + feholdexcept(&curr_excepts); + + /* Raise inexact and overflow exceptions. */ + printf("In x2(): x = %f\n", x=x*2.0); + show_fe_exceptions(); + feclearexcept(FE_INEXACT); /* hide inexact exception from caller */ + + /* Merge caller's exceptions (FE_INVALID) */ + /* with remaining x2's exceptions (FE_OVERFLOW). */ + feupdateenv(&curr_excepts); + return x; +} + +int main(void) +{ + feclearexcept(FE_ALL_EXCEPT); + feraiseexcept(FE_INVALID); /* some computation with invalid argument */ + show_fe_exceptions(); + printf("x2(DBL_MAX) = %f\n", x2(DBL_MAX)); + show_fe_exceptions(); + + return 0; +}</pre></div> <p>Output:</p> +<div class="text source-text"><pre data-language="c">current exceptions raised: FE_INVALID +In x2(): x = inf +current exceptions raised: FE_INEXACT FE_OVERFLOW +x2(DBL_MAX) = inf +current exceptions raised: FE_INVALID FE_OVERFLOW</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.6.4.4 The feupdateenv function (p: 214-215) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.6.4.4 The feupdateenv function (p: 195-196) </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <tr class="t-dsc"> <td> <div><a href="feholdexcept" title="c/numeric/fenv/feholdexcept"> <span class="t-lines"><span>feholdexcept</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> saves the environment, clears all status flags and ignores all future errors <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="feenv" title="c/numeric/fenv/feenv"> <span class="t-lines"><span>fegetenv</span><span>fesetenv</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> saves or restores the current floating-point environment <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td> <div><a href="fe_dfl_env" title="c/numeric/fenv/FE DFL ENV"> <span class="t-lines"><span>FE_DFL_ENV</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> default floating-point environment <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/feupdateenv" title="cpp/numeric/fenv/feupdateenv">C++ documentation</a></span> for <code>feupdateenv</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/fenv/feupdateenv" class="_attribution-link">https://en.cppreference.com/w/c/numeric/fenv/feupdateenv</a> + </p> +</div> |
