名稱空間
變體
操作

std::feraiseexcept

來自 cppreference.com
< cpp‎ | 數值‎ | fenv
 
 
 
浮點環境
函式
feraiseexcept
(C++11)
(C++11)(C++11)
(C++11)(C++11)
宏常量
(C++11)
 
定義於標頭檔案 <cfenv>
int feraiseexcept( int excepts );
(C++11 起)

嘗試引發 `excepts` 中列出的所有浮點異常(浮點異常宏的位或運算結果)。如果其中一個異常是 FE_OVERFLOWFE_UNDERFLOW,則此函式可能還會引發 FE_INEXACT。引發異常的順序未指定,但 FE_OVERFLOWFE_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 文件 中關於 feraiseexcept 的內容