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%2Ffe_dfl_env.html | |
new repository
Diffstat (limited to 'devdocs/c/numeric%2Ffenv%2Ffe_dfl_env.html')
| -rw-r--r-- | devdocs/c/numeric%2Ffenv%2Ffe_dfl_env.html | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/devdocs/c/numeric%2Ffenv%2Ffe_dfl_env.html b/devdocs/c/numeric%2Ffenv%2Ffe_dfl_env.html new file mode 100644 index 00000000..bbc17453 --- /dev/null +++ b/devdocs/c/numeric%2Ffenv%2Ffe_dfl_env.html @@ -0,0 +1,80 @@ + <h1 id="firstHeading" class="firstHeading">FE_DFL_ENV</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">#define FE_DFL_ENV /*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 macro constant <code>FE_DFL_ENV</code> expands to an expression of type <code>const fenv_t*</code>, which points to a full copy of the default floating-point environment, that is, the environment as loaded at program startup.</p> +<p>Additional macros that begin with <code>FE_</code> followed by uppercase letters, and have the type <code>const fenv_t*</code>, may be supported by an implementation.</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> + +#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"); +} + +void show_fe_rounding_method(void) +{ + printf("current rounding method: "); + switch (fegetround()) { + case FE_TONEAREST: printf ("FE_TONEAREST"); break; + case FE_DOWNWARD: printf ("FE_DOWNWARD"); break; + case FE_UPWARD: printf ("FE_UPWARD"); break; + case FE_TOWARDZERO: printf ("FE_TOWARDZERO"); break; + default: printf ("unknown"); + }; + printf("\n"); +} + +void show_fe_environment(void) +{ + show_fe_exceptions(); + show_fe_rounding_method(); +} + +int main() +{ + printf("On startup:\n"); + show_fe_environment(); + + // Change environment + fesetround(FE_DOWNWARD); // change rounding mode + feraiseexcept(FE_INVALID); // raise exception + printf("\nBefore restoration:\n"); + show_fe_environment(); + + fesetenv(FE_DFL_ENV); // restore + printf("\nAfter restoring default environment:\n"); + show_fe_environment(); +}</pre></div> <p>Output:</p> +<div class="text source-text"><pre data-language="c">On startup: +current exceptions raised: none +current rounding method: FE_TONEAREST + +Before restoration: +current exceptions raised: FE_INVALID +current rounding method: FE_DOWNWARD + +After restoring default environment: +current exceptions raised: none +current rounding method: FE_TONEAREST</pre></div> </div> <h3 id="References"> References</h3> <ul> +<li> C11 standard (ISO/IEC 9899:2011): </li> +<ul><li> 7.6/9 Floating-point environment <fenv.h> (p: 208) </li></ul> +<li> C99 standard (ISO/IEC 9899:1999): </li> +<ul><li> 7.6/8 Floating-point environment <fenv.h> (p: 188-189) </li></ul> +</ul> <h3 id="See_also"> See also</h3> <table class="t-dsc-begin"> <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="feupdateenv" title="c/numeric/fenv/feupdateenv"> <span class="t-lines"><span>feupdateenv</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> restores the floating-point environment and raises the previously raise exceptions <br> <span class="t-mark">(function)</span> </td> +</tr> <tr class="t-dsc"> <td colspan="2"> <span><a href="https://en.cppreference.com/w/cpp/numeric/fenv/FE_DFL_ENV" title="cpp/numeric/fenv/FE DFL ENV">C++ documentation</a></span> for <code>FE_DFL_ENV</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/FE_DFL_ENV" class="_attribution-link">https://en.cppreference.com/w/c/numeric/fenv/FE_DFL_ENV</a> + </p> +</div> |
