From 754bbf7a25a8dda49b5d08ef0d0443bbf5af0e36 Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 7 Apr 2024 13:41:34 -0500 Subject: new repository --- devdocs/c/numeric%2Ffenv%2Ffeexceptflag.html | 68 ++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 devdocs/c/numeric%2Ffenv%2Ffeexceptflag.html (limited to 'devdocs/c/numeric%2Ffenv%2Ffeexceptflag.html') diff --git a/devdocs/c/numeric%2Ffenv%2Ffeexceptflag.html b/devdocs/c/numeric%2Ffenv%2Ffeexceptflag.html new file mode 100644 index 00000000..04da8f88 --- /dev/null +++ b/devdocs/c/numeric%2Ffenv%2Ffeexceptflag.html @@ -0,0 +1,68 @@ +

fegetexceptflag, fesetexceptflag

Defined in header <fenv.h>
int fegetexceptflag( fexcept_t* flagp, int excepts );
+
(1) (since C99)
int fesetexceptflag( const fexcept_t* flagp, int excepts );
+
(2) (since C99)

1) Attempts to obtain the full contents of the floating-point exception flags that are listed in the bitmask argument excepts, which is a bitwise OR of the floating-point exception macros.

+

2) Attempts to copy the full contents of the floating-point exception flags that are listed in excepts from flagp into the floating-point environment. Does not raise any exceptions, only modifies the flags.

+

The full contents of a floating-point exception flag is not necessarily a boolean value indicating whether the exception is raised or cleared. For example, it may be a struct which includes the boolean status and the address of the code that triggered the exception. These functions obtain all such content and obtain/store it in flagp in implementation-defined format.

+

Parameters

+ + +
flagp - pointer to an fexcept_t object where the flags will be stored or read from
excepts - bitmask listing the exception flags to get/set

Return value

​0​ on success, non-zero otherwise.

+

Example

#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");
+}
+ 
+int main(void)
+{
+    fexcept_t excepts;
+ 
+    /* Setup a "current" set of exception flags. */
+    feraiseexcept(FE_INVALID);
+    show_fe_exceptions();
+ 
+    /* Save current exception flags. */
+    fegetexceptflag(&excepts,FE_ALL_EXCEPT);
+ 
+    /* Temporarily raise two other exceptions. */
+    feclearexcept(FE_ALL_EXCEPT);
+    feraiseexcept(FE_OVERFLOW | FE_INEXACT);
+    show_fe_exceptions();
+ 
+    /* Restore previous exception flags. */
+    fesetexceptflag(&excepts,FE_ALL_EXCEPT);
+    show_fe_exceptions();
+ 
+    return 0;
+}

Output:

+
current exceptions raised: FE_INVALID
+current exceptions raised: FE_INEXACT FE_OVERFLOW
+current exceptions raised: FE_INVALID

References

See also

+
C++ documentation for fegetexceptflag, fesetexceptflag
+

+ © cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
+ https://en.cppreference.com/w/c/numeric/fenv/feexceptflag +

+
-- cgit v1.2.3