名稱空間
變體
操作

std::fetestexcept

來自 cppreference.com
< cpp‎ | 數值‎ | fenv
 
 
 
浮點環境
函式
fetestexcept
(C++11)
(C++11)(C++11)
(C++11)(C++11)
宏常量
(C++11)
 
定義於標頭檔案 <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 文件 關於 fetestexcept