名稱空間
變體
操作

std::feclearexcept

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

嘗試清除在位掩碼引數 excepts 中列出的浮點異常,excepts浮點異常宏的按位或。

目錄

[編輯] 引數

excepts - 列出要清除的異常標誌的位掩碼

[編輯] 返回值

0 如果所有指示的異常都已成功清除,或者如果 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 文件 關於 feclearexcept