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

feraiseexcept

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

Attempts to raise all floating-point exceptions listed in excepts (a bitwise OR of the floating-point exception macros). If one of the exceptions is FE_OVERFLOW or FE_UNDERFLOW, this function may additionally raise FE_INEXACT. The order in which the exceptions are raised is unspecified, except that FE_OVERFLOW and FE_UNDERFLOW are always raised before FE_INEXACT.

+

Parameters

+ +
excepts - bitmask listing the exception flags to raise

Return value

​0​ if all listed exceptions were raised, non-zero value 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");
+    feclearexcept(FE_ALL_EXCEPT);
+    printf("\n");
+}
+ 
+double some_computation(void)
+{
+    /* Computation reaches a state that causes overflow. */
+    int r = feraiseexcept(FE_OVERFLOW | FE_INEXACT);
+    printf("feraiseexcept() %s\n", (r?"fails":"succeeds"));
+    return 0.0;
+}
+ 
+int main(void)
+{
+    some_computation();
+    show_fe_exceptions();
+ 
+    return 0;
+}

Output:

+
feraiseexcept() succeeds
+current exceptions raised:  FE_INEXACT FE_OVERFLOW

References

See also

+ + +
+
(C99)
clears the specified floating-point status flags
(function)
+
(C99)
determines which of the specified floating-point status flags are set
(function)
C++ documentation for feraiseexcept
+

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

+
-- cgit v1.2.3