?
This document uses PHP Chinese website manual Release
在頭文件<fenv.h>中定義 | ||
---|---|---|
int feraiseexcept(int excepts); | (自C99以來) |
嘗試提升excepts中列出的所有浮點(diǎn)異常(浮點(diǎn)異常宏的按位或)。 如果其中一個(gè)例外是FE_OVERFLOW或FE_UNDERFLOW,則此函數(shù)可能會(huì)額外引發(fā)FE_INEXACT。 除非在FE_INEXACT之前始終引發(fā)FE_OVERFLOW和FE_UNDERFLOW,否則未指定異常的順序。
excepts | - | bitmask listing the exception flags to raise |
---|
如果列出的所有異常均為0,則返回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"); feclearexcept(FE_ALL_EXCEPT); printf("\n");} double some_computation(void){ /* Computation reaches a state that causes overflow. */ int r = feraiseexcept(FE_OVERFLOW | FE_INEXACT); printf("feraiseexcept() %s\n", (r?"fails":"succeeds")); return 0.0;} int main(void){ some_computation(); show_fe_exceptions(); return 0;}
輸出:
feraiseexcept() succeeds current exceptions raised: FE_INEXACT FE_OVERFLOW
C11標(biāo)準(zhǔn)(ISO / IEC 9899:2011):
7.6.2.3 feraiseexcept函數(shù)(p:210)
C99標(biāo)準(zhǔn)(ISO / IEC 9899:1999):
7.6.2.3 feraiseexcept函數(shù)(p:191)
feclearexcept(C99) | 清除指定的浮點(diǎn)狀態(tài)標(biāo)志(函數(shù)) |
---|---|
fetestexcept(C99) | 確定哪個(gè)指定的浮點(diǎn)狀態(tài)標(biāo)志被設(shè)置(功能) |
| 用于feraiseexcept的C ++文檔 |