?
本文檔使用 php中文網(wǎng)手冊 發(fā)布
在頭文件<fenv.h>中定義 | ||
---|---|---|
int feupdateenv(const fenv_t * envp); | (自C99以來) |
首先,記住當前浮點異常,然后從envp指向的對象(類似于fesetenv)恢復(fù)浮點環(huán)境,然后引發(fā)已保存的浮點異常。
這個功能可以用來結(jié)束早期調(diào)用feholdexcept所建立的不間斷模式。
envp | - | pointer to the object of type fenv_t set by an earlier call to feholdexcept or fegetenv or equal to 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_OVERFLOWx2(DBL_MAX) = inf current exceptions raised: FE_INVALID FE_OVERFLOW
C11標準(ISO / IEC 9899:2011):
7.6.4.4 feupdateenv函數(shù)(p:214-215)
C99標準(ISO / IEC 9899:1999):
7.6.4.4 feupdateenv函數(shù)(p:195-196)
feholdexcept(C99) | 保存環(huán)境,清除所有狀態(tài)標志并忽略所有將來的錯誤(功能) |
---|---|
fegetenvfesetenv(C99) | 保存或恢復(fù)當前的浮點環(huán)境(功能) |
FE_DFL_ENV(C99) | 默認浮點環(huán)境(宏常量) |
| feupdateenv的C ++文檔 |