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%2Ffetestexcept.html | 60 ++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 devdocs/c/numeric%2Ffenv%2Ffetestexcept.html (limited to 'devdocs/c/numeric%2Ffenv%2Ffetestexcept.html') diff --git a/devdocs/c/numeric%2Ffenv%2Ffetestexcept.html b/devdocs/c/numeric%2Ffenv%2Ffetestexcept.html new file mode 100644 index 00000000..6e100461 --- /dev/null +++ b/devdocs/c/numeric%2Ffenv%2Ffetestexcept.html @@ -0,0 +1,60 @@ +

fetestexcept

Defined in header <fenv.h>
int fetestexcept( int excepts );
+
(since C99)

Determines which of the specified subset of the floating-point exceptions are currently set. The argument excepts is a bitwise OR of the floating-point exception macros.

+

Parameters

+ +
excepts - bitmask listing the exception flags to test

Return value

Bitwise OR of the floating-point exception macros that are both included in excepts and correspond to floating-point exceptions currently set.

+

Example

#include <stdio.h>
+#include <math.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");
+}
+ 
+int main(void)
+{
+    /* Show default set of exception flags. */
+    show_fe_exceptions();
+ 
+    /* Perform some computations which raise exceptions. */
+    printf("1.0/0.0     = %f\n", 1.0/0.0);        /* FE_DIVBYZERO            */
+    printf("1.0/10.0    = %f\n", 1.0/10.0);       /* FE_INEXACT              */
+    printf("sqrt(-1)    = %f\n", sqrt(-1));       /* FE_INVALID              */
+    printf("DBL_MAX*2.0 = %f\n", DBL_MAX*2.0);    /* FE_INEXACT FE_OVERFLOW  */
+    printf("nextafter(DBL_MIN/pow(2.0,52),0.0) = %.1f\n",
+           nextafter(DBL_MIN/pow(2.0,52),0.0));   /* FE_INEXACT FE_UNDERFLOW */
+    show_fe_exceptions();
+ 
+    return 0;
+}

Output:

+
current exceptions raised:  none
+1.0/0.0     = inf
+1.0/10.0    = 0.100000
+sqrt(-1)    = -nan
+DBL_MAX*2.0 = inf
+nextafter(DBL_MIN/pow(2.0,52),0.0) = 0.0
+current exceptions raised:  FE_DIVBYZERO FE_INEXACT FE_INVALID FE_OVERFLOW FE_UNDERFLOW

References

See also

+ +
+
(C99)
clears the specified floating-point status flags
(function)
C++ documentation for fetestexcept
+

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

+
-- cgit v1.2.3