feupdateenv
來自 cppreference.com
定義於標頭檔案 <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