Namespaces
Variants

feupdateenv

From cppreference.net
< c ‎ | numeric ‎ | fenv
헤더 파일에 정의됨 <fenv.h>
int feupdateenv ( const fenv_t * envp ) ;
(C99부터)

먼저 현재 발생한 부동 소수점 예외들을 기억한 다음, envp 가 가리키는 객체에서 부동 소수점 환경을 복원하고( fesetenv 와 유사), 이후 저장되었던 부동 소수점 예외들을 발생시킵니다.

이 함수는 이전 호출에서 설정된 비정지 모드를 종료하는 데 사용될 수 있습니다. feholdexcept .

목차

매개변수

envp - fenv_t 타입의 객체를 가리키는 포인터로, feholdexcept 또는 fegetenv 의 이전 호출로 설정되었거나 FE_DFL_ENV 와 동일함

반환값

0 성공 시 0, 그렇지 않으면 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 표준 (ISO/IEC 9899:2011):
  • 7.6.4.4 feupdateenv 함수 (p: 214-215)
  • C99 표준 (ISO/IEC 9899:1999):
  • 7.6.4.4 feupdateenv 함수 (p: 195-196)

참조 항목

환경을 저장하고, 모든 상태 플래그를 지우며, 이후 모든 오류를 무시함
(함수)
현재 부동 소수점 환경을 저장하거나 복원함
(함수)
기본 부동 소수점 환경
(매크로 상수)
C++ 문서 for feupdateenv