名前空間
変種
操作

feupdateenv

提供: cppreference.com
< c‎ | numeric‎ | fenv
ヘッダ <fenv.h> で定義
int feupdateenv( const fenv_t* envp );
(C99以上)

まず、現在発生している浮動小数点例外を記憶し、 envp の指すオブジェクトから浮動小数点環境を復元し (fesetenv と同様)、それから、保存していた浮動小数点例外を発生させます。

この関数は feholdexcept の以前の呼び出しによって確立された非停止モードを終了するために使用することができます。

目次

[編集] 引数

envp - feholdexcept または fegetenv の以前の呼び出しによって取得した fenv_t 型のオブジェクトを指すポインタ、または FE_DFL_ENV

[編集] 戻り値

成功した場合は 0、そうでなければ非ゼロ。

[編集]

#include <stdio.h>
#include <fenv.h>
#include <float.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");
}
 
double x2 (double x)   /* times two */
{
    fenv_t curr_excepts;
 
    /* Save and clear current f-p environment. */
    feholdexcept(&curr_excepts);
 
    /* Raise inexact and overflow exceptions. */
    printf("In x2():  x = %f\n", x=x*2.0);
    show_fe_exceptions();
    feclearexcept(FE_INEXACT);   /* hide inexact exception from caller */
 
    /* Merge caller's exceptions (FE_INVALID)        */
    /* with remaining x2's exceptions (FE_OVERFLOW). */
    feupdateenv(&curr_excepts);
    return x;
}
 
int main(void)
{    
    feclearexcept(FE_ALL_EXCEPT);
    feraiseexcept(FE_INVALID);   /* some computation with invalid argument */
    show_fe_exceptions();
    printf("x2(DBL_MAX) = %f\n", x2(DBL_MAX));
    show_fe_exceptions();
 
    return 0;
}

出力:

current exceptions raised:  FE_INVALID
In x2():  x = inf
current exceptions raised:  FE_INEXACT FE_OVERFLOW
x2(DBL_MAX) = inf
current exceptions raised:  FE_INVALID FE_OVERFLOW

[編集] 参考文献

  • C11 standard (ISO/IEC 9899:2011):
  • 7.6.4.4 The feupdateenv function (p: 214-215)
  • C99 standard (ISO/IEC 9899:1999):
  • 7.6.4.4 The feupdateenv function (p: 195-196)

[編集] 関連項目

環境を保存し、すべてのステータスフラグをクリアし、今後のすべてのエラーを無視します
(関数) [edit]
浮動小数点環境を保存または復元します
(関数) [edit]
デフォルトの浮動小数点環境
(マクロ定数) [edit]
feupdateenvC++リファレンス