C <fenv.h> - feclearexcept() Function
The C <fenv.h> feclearexcept() function attempts to clear the floating-point exceptions specified by excepts. Programs calling this function shall ensure that pragma FENV_ACCESS is enabled for the call.
Syntax
int feclearexcept (int excepts);
Parameters
excepts |
Specify bitmask listing the floating-point exception flags to clear.
Certain library implementations may define additional macro constants in <fenv.h> to identify additional floating-point exceptions (with their corresponding macros also beginning with FE_). |
Return Value
Returns 0 if all exceptions in excepts were successfully cleared or if excepts is zero. Returns a non-zero value otherwise.
Exception
This function never throws exceptions.
Example:
In the example below, the feclearexcept() function is used to clear floating-point exceptions.
#include <stdio.h> #include <fenv.h> #include <math.h> #pragma STDC FENV_ACCESS ON int main (){ printf("sqrt(-1.0) = %f\n", sqrt(-1)); if(fetestexcept(FE_INVALID)) printf("Domain error is reported.\n"); else printf("Domain error is not reported.\n"); //clearing FE_INVALID and FE_INEXACT exceptions //bitwise OR is used to combine number of exceptions feclearexcept(FE_INVALID | FE_INEXACT); printf("sqrt(25) = %f\n", sqrt(25)); if(fetestexcept(FE_INVALID)) printf("Domain error is reported.\n"); else printf("Domain error is not reported.\n"); return 0; }
The output of the above code will be:
sqrt(-1.0) = -nan Domain error is reported. sqrt(25) = 5.000000 Domain error is not reported.
❮ C <fenv.h> Library