名前空間
変種
操作

fegetexceptflag, fesetexceptflag

From 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) excepts 引数で指定されたビットマスクにリストされている浮動小数点例外フラグの完全な内容を取得しようとします。excepts は、浮動小数点例外マクロ のビットごとの OR です。

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 The fegetexceptflag function (p: 210)
  • 7.6.2.4 The fesetexceptflag function (p: 211)
  • C99標準 (ISO/IEC 9899:1999)
  • 7.6.2.2 The fegetexceptflag function (p: 191)
  • 7.6.2.4 The fesetexceptflag function (p: 192)

[編集] 関連項目

C++ ドキュメント: fegetexceptflag, fesetexceptflag
English 日本語 中文(简体) 中文(繁體)