在线文档教程
C++
数字 | Numerics

std::feraiseexcept

STD::除了

Defined in header
int feraiseexcept( int excepts (since C++11)

中列出的所有浮点异常的引发尝试。excepts%28a按位或浮点异常宏29%。如果其中一个例外是FE_OVERFLOWFE_UNDERFLOW,此功能可能会增加FE_INEXACT.提出例外情况的先后次序未予指明,但FE_OVERFLOWFE_UNDERFLOW总是在FE_INEXACT...

参数

excepts-bitmask listing the exception flags to raise

返回值

​0​如果引发所有列出的异常,则为非零值。

二次

#include <iostream> #include <cfenv> #pragma STDC FENV_ACCESS ON int main() { std::feclearexcept(FE_ALL_EXCEPT int r = std::feraiseexcept(FE_UNDERFLOW | FE_DIVBYZERO std::cout << "Raising divbyzero and underflow simultaneously " << (r?"fails":"succeeds") << " and results in\n"; int e = std::fetestexcept(FE_ALL_EXCEPT if (e & FE_DIVBYZERO) { std::cout << "division by zero\n"; } if (e & FE_INEXACT) { std::cout << "inexact\n"; } if (e & FE_INVALID) { std::cout << "invalid\n"; } if (e & FE_UNDERFLOW) { std::cout << "underflow\n"; } if (e & FE_OVERFLOW) { std::cout << "overflow\n"; } }

二次

产出:

二次

Raising divbyzero and underflow simultaneously succeeds and results in division by zero underflow

二次

另见

feclearexcept (C++11)clears the specified floating-point status flags (function)
fetestexcept (C++11)determines which of the specified floating-point status flags are set (function)

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/NUMERE/FINV/feraiseout