std::feraiseexcept
來自 cppreference.com
定義於標頭檔案 <cfenv> |
||
int feraiseexcept( int excepts ); |
(C++11 起) | |
嘗試引發 `excepts` 中列出的所有浮點異常(浮點異常宏的位或運算結果)。如果其中一個異常是 FE_OVERFLOW 或 FE_UNDERFLOW,則此函式可能還會引發 FE_INEXACT。引發異常的順序未指定,但 FE_OVERFLOW 和 FE_UNDERFLOW 總是先於 FE_INEXACT 引發。
目錄 |
[編輯] 引數
excepts | - | 列出要引發的異常標誌的位掩碼 |
[編輯] 返回值
如果所有列出的異常都被引發,則為 0,否則為非零值。
[編輯] 示例
執行此程式碼
#include <cfenv> #include <iostream> // #pragma STDC FENV_ACCESS ON int main() { std::feclearexcept(FE_ALL_EXCEPT); const int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO); std::cout << "Raising divbyzero and underflow simultaneously " << (r ? "fails" : "succeeds") << " and results in\n"; const int e = std::fetestexcept(FE_ALL_EXCEPT); if (e & FE_DIVBYZERO) std::cout << "division by zero\n"; if (e & FE_INEXACT) std::cout << "inexact\n"; if (e & FE_INVALID) std::cout << "invalid\n"; if (e & FE_UNDERFLOW) std::cout << "underflow\n"; if (e & FE_OVERFLOW) std::cout << "overflow\n"; }
輸出
Raising divbyzero and underflow simultaneously succeeds and results in division by zero underflow
[編輯] 參閱
(C++11) |
清除指定的浮點狀態標誌 (函式) |
(C++11) |
確定哪些指定的浮點狀態標誌已設定 (函式) |
C 文件 中關於 feraiseexcept 的內容
|