fegetexceptflag, fesetexceptflag
提供: cppreference.com
ヘッダ <fenv.h> で定義
|
||
int fegetexceptflag( fexcept_t* flagp, int excepts ); |
(1) | (C99以上) |
int fesetexceptflag( const fexcept_t* flagp, int excepts ); |
(2) | (C99以上) |
1) ビットマスク引数 excepts
で指定された浮動小数点例外フラグの完全な内容の取得を試みます。 excepts
は浮動小数点例外マクロのビット単位の論理和です。
2) excepts
で指定された浮動小数点例外フラグの完全な内容の flagp
から浮動小数点環境へのコピーを試みます。 いかなる例外も発生させません。 フラグを変更するだけです。
浮動小数点例外フラグの完全な内容は、例外が発生したかクリアされたかを表すブーリアン値であるとは限りません。 例えば、ブーリアンのステータスフラグと例外の原因となったコードのアドレスを持つ構造体かもしれません。 これらの関数はそのような内容をすべて取得し、それを flagp
に処理系定義のフォーマットで格納または取得します。
目次 |
[編集] 引数
flagp | - | フラグを格納するまたは読み込む std::fexcept_t オブジェクトを指すポインタ |
excepts | - | 取得または設定する例外フラグを指定するビットマスク |
[編集] 戻り値
成功した場合は 0、そうでなければ非ゼロ。
[編集] 例
Run this code
#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 standard (ISO/IEC 9899:2011):
- 7.6.2.2 The fegetexceptflag function (p: 210)
- 7.6.2.4 The fesetexceptflag function (p: 211)
- C99 standard (ISO/IEC 9899:1999):
- 7.6.2.2 The fegetexceptflag function (p: 191)
- 7.6.2.4 The fesetexceptflag function (p: 192)
[編集] 関連項目
fegetexceptflag, fesetexceptflag の C++リファレンス
|