C ++ fetestexcept () - C ++ Standardbibliotek

Fetestexcept () -funktionen i C ++ avgör vilken av den angivna delmängden av undantagen för flytpunkten som för närvarande är inställd.

Funktionen fetestexcept () definieras i rubrikfilen.

fetestexcept () prototyp

 int fetestexcept (int excepts);

Funktionen fetestexcept () testar om det undantag för flytpunkt som anges av excepts för närvarande är inställt. Argumentet undantag är en bitvis ELLER av makroen för undantagsflytande.

fetestexcept () Parametrar

  • excepts: Bitmask som listar undantagsflaggorna som ska testas.

fetestexcept () Returvärde

  • Bitvis ELLER av undantagsmakronen för flytande punkter som båda ingår i undantagen och motsvarar de för närvarande inställda undantagen för flytpunkter.

Exempel: Hur fungerar fetestexcept () -funktionen?

 #include #include #include #pragma STDC FENV_ACCESS ON using namespace std; void print_exceptions() ( cout << "Raised exceptions: "; if(fetestexcept(FE_ALL_EXCEPT)) ( if(fetestexcept(FE_DIVBYZERO)) cout << "FE_DIVBYZERO "; if(fetestexcept(FE_INEXACT)) cout << "FE_INEXACT "; if(fetestexcept(FE_INVALID)) cout << "FE_INVALID "; if(fetestexcept(FE_OVERFLOW)) cout << "FE_OVERFLOW "; if(fetestexcept(FE_UNDERFLOW)) cout << "FE_UNDERFLOW "; ) else cout << "None"; cout << endl; ) int main(void) ( print_exceptions(); feraiseexcept(FE_INVALID|FE_DIVBYZERO); print_exceptions(); feclearexcept(FE_ALL_EXCEPT); print_exceptions(); return 0; )

När du kör programmet blir resultatet:

 Upphöjda undantag: Inga Upphöjda undantag: FE_DIVBYZERO FE_INVALID Upphöjda undantag: Inga

Intressanta artiklar...