Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

1 Answer
Samual Sam

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

Advertisements

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.