C ++ 'daki fetestexcept () işlevi, kayan nokta istisnalarının belirtilen alt kümesinden hangisinin şu anda ayarlandığını belirler.
Fetestexcept () işlevi başlık dosyasında tanımlanmıştır.
fetestexcept () prototip
int fetestexcept (int excepts);
Fetestexcept () işlevi, istisnalar tarafından belirtilen kayan nokta istisnasının şu anda ayarlanıp ayarlanmadığını test eder. Excepts argümanı, kayan nokta istisna makrolarının bitsel VEYA şeklindedir.
fetestexcept () Parametreler
- excepts: Test edilecek istisna bayraklarını listeleyen bit maskesi.
fetestexcept () Dönüş değeri
- Her ikisi de istisnalara dahil olan ve şu anda ayarlanan kayan nokta istisnalarına karşılık gelen kayan nokta istisna makrolarının bit tabanlı OR.
Örnek: fetestexcept () işlevi nasıl çalışır?
#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; )
Programı çalıştırdığınızda, çıktı:
Yükseltilmiş istisnalar: Yok Artan istisnalar: FE_DIVBYZERO FE_INVALID Yükseltilmiş istisnalar: Yok