Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      FE_DFL_ENV

      From cppreference.com
      <c‎ |numeric‎ |fenv
       
       
       
       
      Defined in header<fenv.h>
      #define FE_DFL_ENV  /*implementation defined*/
      (since C99)

      The macro constantFE_DFL_ENV expands to an expression of typeconst fenv_t*, which points to a full copy of the default floating-point environment, that is, the environment as loaded at program startup.

      Additional macros that begin withFE_ followed by uppercase letters, and have the typeconst fenv_t*, may be supported by an implementation.

      [edit]Example

      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");} void show_fe_rounding_method(void){printf("current rounding method:    ");switch(fegetround()){caseFE_TONEAREST:printf("FE_TONEAREST");break;caseFE_DOWNWARD:printf("FE_DOWNWARD");break;caseFE_UPWARD:printf("FE_UPWARD");break;caseFE_TOWARDZERO:printf("FE_TOWARDZERO");break;default:printf("unknown");};printf("\n");} void show_fe_environment(void){    show_fe_exceptions();    show_fe_rounding_method();}  int main(){printf("On startup:\n");    show_fe_environment(); // Change environmentfesetround(FE_DOWNWARD);// change rounding modeferaiseexcept(FE_INVALID);// raise exceptionprintf("\nBefore restoration:\n");    show_fe_environment(); fesetenv(FE_DFL_ENV);// restoreprintf("\nAfter restoring default environment:\n");    show_fe_environment();}

      Output:

      On startup:current exceptions raised:  nonecurrent rounding method:    FE_TONEAREST Before restoration:current exceptions raised:  FE_INVALIDcurrent rounding method:    FE_DOWNWARD After restoring default environment:current exceptions raised:  nonecurrent rounding method:    FE_TONEAREST

      [edit]References

      • C11 standard (ISO/IEC 9899:2011):
      • 7.6/9 Floating-point environment <fenv.h> (p: 208)
      • C99 standard (ISO/IEC 9899:1999):
      • 7.6/8 Floating-point environment <fenv.h> (p: 188-189)

      [edit]See also

      saves or restores the current floating-point environment
      (function)[edit]
      restores the floating-point environment and raises the previously raise exceptions
      (function)[edit]
      C++ documentation forFE_DFL_ENV
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=c/numeric/fenv/FE_DFL_ENV&oldid=133803"

      [8]ページ先頭

      ©2009-2025 Movatter.jp