?
本文檔使用 PHP中文網(wǎng)手冊 發(fā)布
在頭文件<fenv.h>中定義 | ||
---|---|---|
int fegetexceptflag(fexcept_t * flagp,int excepts); | (1) | (自C99以來) |
int fesetexceptflag(const fexcept_t * flagp,int excepts); | (2) | (自C99以來) |
1)嘗試獲取位掩碼參數(shù)excepts中列出的浮點異常標(biāo)志的全部內(nèi)容,這是浮點異常宏的按位或。
2)嘗試將浮點異常標(biāo)志的全部內(nèi)容復(fù)制到浮點環(huán)境中。 不會引發(fā)任何異常,只會修改標(biāo)志。
浮點異常標(biāo)志的全部內(nèi)容不一定是一個布爾值,指示是否引發(fā)或清除異常。 例如,它可能是一個包含布爾狀態(tài)和觸發(fā)異常的代碼地址的結(jié)構(gòu)。 這些函數(shù)獲取所有這些內(nèi)容并以實現(xiàn)定義的格式將其存儲在flagp中。
flagp | - | 指向?qū)⒋鎯蜃x取標(biāo)志的fexcept_t對象的指針 |
---|---|---|
excepts | - | 位掩碼列出異常標(biāo)志以獲取/設(shè)置 |
成功時為0,否則為非零。
#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");} int main(void){ fexcept_t excepts; /* Setup a "current" set of exception flags. */ feraiseexcept(FE_INVALID); show_fe_exceptions(); /* Save current exception flags. */ fegetexceptflag(&excepts,FE_ALL_EXCEPT); /* Temporarily raise two other exceptions. */ feclearexcept(FE_ALL_EXCEPT); feraiseexcept(FE_OVERFLOW | FE_INEXACT); show_fe_exceptions(); /* Restore previous exception flags. */ fesetexceptflag(&excepts,FE_ALL_EXCEPT); show_fe_exceptions(); return 0;}
輸出:
current exceptions raised: FE_INVALID current exceptions raised: FE_INEXACT FE_OVERFLOW current exceptions raised: FE_INVALID
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.6.2.2 fegetexcept標(biāo)志功能(p:210)
7.6.2.4 fesetexcept標(biāo)志功能(p:211)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.6.2.2 fegetexcept標(biāo)志功能(p:191)
7.6.2.4 fesetexceptflag函數(shù)(p:192)
| 用于fegetexceptflag,fesetexceptflag的C ++文檔 |
|:----|