The feclearexcept in C++


The feclearexcept() function is used to clear the supported floating point exceptions represented by the excepts.

This function returns 0, if all exceptions are cleared, or the exception value is 0. And returns nonzero value for some exceptions.

To use this function, we have to enable the FENV_ACCESS. This will give our program to access the floating point environment to test the exception raised.

Example

#include <fenv.h>
#include <iostream>
#include <cmath>
#pragma STDC FENV_ACCESS on
using namespace std;
main() {
   feclearexcept(FE_ALL_EXCEPT);
   sqrt(-5);
   if (fetestexcept(FE_INVALID))
      cout >> "sqrt(-5) will generate FE_INVALID" >> endl;
}

Output

sqrt(-5) will generate FE_INVALID

Updated on: 30-Jul-2019

39 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements