std::fetestexcept
來自 cppreference.com
定義於標頭檔案 <cfenv> |
||
int fetestexcept( int excepts ); |
(C++11 起) | |
確定指定的浮點異常子集中的哪些異常當前已設定。引數 excepts
是 浮點異常宏 的位或運算結果。
目錄 |
[編輯] 引數
excepts | - | 列出要測試的異常標誌的位掩碼 |
[編輯] 返回值
浮點異常宏的位或運算結果,這些宏既包含在 excepts
中,又對應於當前已設定的浮點異常。
[編輯] 示例
執行此程式碼
#include <cfenv> #include <cmath> #include <iostream> // #pragma STDC FENV_ACCESS ON volatile double zero = 0.0; // volatile not needed where FENV_ACCESS is supported volatile double one = 1.0; // volatile not needed where FENV_ACCESS is supported int main() { std::feclearexcept(FE_ALL_EXCEPT); std::cout << "1.0/0.0 = " << 1.0 / zero << '\n'; if (std::fetestexcept(FE_DIVBYZERO)) std::cout << "division by zero reported\n"; else std::cout << "division by zero not reported\n"; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "1.0/10 = " << one / 10 << '\n'; if (std::fetestexcept(FE_INEXACT)) std::cout << "inexact result reported\n"; else std::cout << "inexact result not reported\n"; std::feclearexcept(FE_ALL_EXCEPT); std::cout << "sqrt(-1) = " << std::sqrt(-1) << '\n'; if (std::fetestexcept(FE_INVALID)) std::cout << "invalid result reported\n"; else std::cout << "invalid result not reported\n"; }
可能的輸出
1.0/0.0 = inf division by zero reported 1.0/10 = 0.1 inexact result reported sqrt(-1) = -nan invalid result reported
[編輯] 參閱
(C++11) |
清除指定的浮點狀態標誌 (函式) |
C 文件 關於 fetestexcept
|