Facebook Page Twitter Page LinkedIn Page
× C Standard Library


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.

MacrosDescription
FE_DIVBYZERO Pole error exception occurred in an earlier floating-point operation.
FE_INEXACT Inexact result exception occurred in an earlier floating-point operation (rounding was necessary to store the result).
FE_INVALID Invalid argument exception occurred (domain error occurred) in an earlier floating-point operation.
FE_OVERFLOW Overflow range error exception occurred in an earlier floating-point operation (result was too large to be representable).
FE_UNDERFLOW Underflow range error exception occurred in an earlier floating-point operation (result was subnormal with a loss of precision).
FE_ALL_EXCEPT Bitwise OR of all supported floating-point exceptions.

Certain library implementations may define additional macro constants in <fenv> 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

5