?
Dieses Dokument verwendet PHP-Handbuch für chinesische Websites Freigeben
在頭文件<fenv.h>中定義 | ||
---|---|---|
#define FE_DFL_ENV / *實(shí)現(xiàn)定義* / | (自C99以來) |
宏常量FE_DFL_ENV擴(kuò)展為類型const fenv_t *的表達(dá)式,該表達(dá)式指向默認(rèn)浮點(diǎn)環(huán)境的完整副本,即在程序啟動(dòng)時(shí)加載的環(huán)境。
其他以FE_開頭,后跟大寫字母并且類型為const fenv_t *的宏可以由實(shí)現(xiàn)支持。
#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()) { case FE_TONEAREST: printf ("FE_TONEAREST"); break; case FE_DOWNWARD: printf ("FE_DOWNWARD"); break; case FE_UPWARD: printf ("FE_UPWARD"); break; case FE_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 environment fesetround(FE_DOWNWARD); // change rounding mode feraiseexcept(FE_INVALID); // raise exception printf("\nBefore restoration:\n"); show_fe_environment(); fesetenv(FE_DFL_ENV); // restore printf("\nAfter restoring default environment:\n"); show_fe_environment();}
輸出:
On startup:current exceptions raised: none current rounding method: FE_TONEAREST Before restoration:current exceptions raised: FE_INVALID current rounding method: FE_DOWNWARD After restoring default environment:current exceptions raised: none current rounding method: FE_TONEAREST
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.6 / 9浮點(diǎn)環(huán)境<fenv.h>(p:208)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.6 / 8浮點(diǎn)環(huán)境<fenv.h>(p:188-189)
fegetenvfesetenv(C99) | 保存或恢復(fù)當(dāng)前的浮點(diǎn)環(huán)境(功能) |
---|---|
feupdateenv(C99) | 恢復(fù)浮點(diǎn)環(huán)境并引發(fā)以前引發(fā)的異常(函數(shù)) |
| FE_DFL_ENV的C ++文檔 |