De functie feholdexcept () in C ++ slaat eerst de huidige zwevende-komma-omgeving op in een fenv_t-object en wist vervolgens alle zwevende-komma-statusvlaggen.
De functie feholdexcept () is gedefinieerd in het header-bestand.
feholdexcept () prototype
int feholdexcept (fenv_t * envp);
De functie feholdexcept () slaat de huidige drijvende-komma-omgeving op naar het object dat door envp wordt aangeduid zoals gedaan door fegetenv () en wist alle statusvlaggen met drijvende-komma.
Ten slotte installeert het de non-stop modus zodat de toekomstige floating-point uitzonderingen de uitvoering niet zullen onderbreken, totdat de floating-point omgeving hersteld is door feupdateenv of fesetenv aan te roepen.
feholdexcept () Parameters
- envp: Pointer naar een object van het type fenv_t dat de status van de floating point-omgeving opslaat.
feholdexcept () Retourwaarde
- Bij succes retourneert de functie feholdexcept () 0.
- Bij een fout wordt niet-nul geretourneerd.
Voorbeeld: hoe werkt de feholdexcept () -functie?
#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) ( fenv_t envp; /* raise certain exceptions */ feraiseexcept(FE_INVALID|FE_DIVBYZERO); print_exceptions(); /* saves and clears current exceptions */ feholdexcept(&envp); print_exceptions(); /* restores saved exceptions */ feupdateenv(&envp); print_exceptions(); return 0; )
Wanneer u het programma uitvoert, is de uitvoer:
Verhoogde uitzonderingen: FE_DIVBYZERO FE_INVALID Verhoogde uitzonderingen: geen Verhoogde uitzonderingen: FE_DIVBYZERO FE_INVALID