名稱空間
變體
操作

fegetexceptflag, fesetexceptflag

來自 cppreference.com
< c‎ | 數值‎ | fenv
定義於標頭檔案 <fenv.h>
int fegetexceptflag( fexcept_t* flagp, int excepts );
(1) (C99 起)
int fesetexceptflag( const fexcept_t* flagp, int excepts );
(2) (C99 起)

1) 嘗試獲取 bitmask 引數 excepts 中列出的浮點異常標誌的全部內容,excepts浮點異常宏 的按位或。

2) 嘗試將 excepts 中列出的浮點異常標誌的全部內容從 flagp 複製到浮點環境中。不引發任何異常,只修改標誌。

浮點異常標誌的全部內容不一定是一個布林值,指示異常是已引發還是已清除。例如,它可能是一個結構體,其中包括布林狀態和觸發異常的程式碼地址。這些函式獲取所有此類內容,並以實現定義格式在 flagp 中獲取/儲存。

目錄

[編輯] 引數

flagp - 指向 fexcept_t 物件的指標,標誌將儲存或從中讀取
excepts - 列出要獲取/設定的異常標誌的位掩碼

[編輯] 返回值

成功時返回 0,否則返回非零值。

[編輯] 示例

#include <stdio.h>
#include <fenv.h>
 
#pragma STDC FENV_ACCESS ON
 
void show_fe_exceptions(void)
{
    printf("current exceptions raised: ");
    if(fetestexcept(FE_DIVBYZERO))     printf(" FE_DIVBYZERO");
    if(fetestexcept(FE_INEXACT))       printf(" FE_INEXACT");
    if(fetestexcept(FE_INVALID))       printf(" FE_INVALID");
    if(fetestexcept(FE_OVERFLOW))      printf(" FE_OVERFLOW");
    if(fetestexcept(FE_UNDERFLOW))     printf(" FE_UNDERFLOW");
    if(fetestexcept(FE_ALL_EXCEPT)==0) printf(" none");
    printf("\n");
}
 
int main(void)
{
    fexcept_t excepts;
 
    /* Setup a "current" set of exception flags. */
    feraiseexcept(FE_INVALID);
    show_fe_exceptions();
 
    /* Save current exception flags. */
    fegetexceptflag(&excepts,FE_ALL_EXCEPT);
 
    /* Temporarily raise two other exceptions. */
    feclearexcept(FE_ALL_EXCEPT);
    feraiseexcept(FE_OVERFLOW | FE_INEXACT);
    show_fe_exceptions();
 
    /* Restore previous exception flags. */
    fesetexceptflag(&excepts,FE_ALL_EXCEPT);
    show_fe_exceptions();
 
    return 0;
}

輸出

current exceptions raised: FE_INVALID
current exceptions raised: FE_INEXACT FE_OVERFLOW
current exceptions raised: FE_INVALID

[編輯] 參考

  • C11 標準 (ISO/IEC 9899:2011)
  • 7.6.2.2 fegetexceptflag 函式 (p: 210)
  • 7.6.2.4 fesetexceptflag 函式 (p: 211)
  • C99 標準 (ISO/IEC 9899:1999)
  • 7.6.2.2 fegetexceptflag 函式 (p: 191)
  • 7.6.2.4 fesetexceptflag 函式 (p: 192)

[編輯] 參閱

C++ 文件 用於 fegetexceptflag, fesetexceptflag