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

FE_INEXACT

铁[医]德比泽罗[医]不精确的,有限元[医]无效的,有限元[医]溢流,有限元[医]底流[医]全[医]除

Defined in header
#define FE_DIVBYZERO /*implementation defined power of 2*/(since C++11)
#define FE_INEXACT /*implementation defined power of 2*/(since C++11)
#define FE_INVALID /*implementation defined power of 2*/(since C++11)
#define FE_OVERFLOW /*implementation defined power of 2*/(since C++11)
#define FE_UNDERFLOW /*implementation defined power of 2*/(since C++11)
#define FE_ALL_EXCEPT FE_DIVBYZERO | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | \ FE_UNDERFLOW(since C++11)

所有这些宏常数%28除外FE_ALL_EXCEPT%29扩展为整数常量表达式,它是2的不同幂,它唯一地标识所有支持的浮点异常。每个宏只有在支持时才定义。

宏常数FE_ALL_EXCEPT,它扩展到所有其他的按位或FE_*,如果实现不支持浮点异常,则为零。

ConstantExplanation
FE_DIVBYZEROpole error occurred in an earlier floating-point operation
FE_INEXACTinexact result: rounding was necessary to store the result of an earlier floating-point operation
FE_INVALIDdomain error occurred in an earlier floating-point operation
FE_OVERFLOWthe result of the earlier floating-point operation was too large to be representable
FE_UNDERFLOWthe result of the earlier floating-point operation was subnormal with a loss of precision
FE_ALL_EXCEPTbitwise OR of all supported floating-point exceptions

实现可以在<cfenv>若要标识其他浮点异常,请执行以下操作。所有这些常量都以FE_后面至少有一个大写字母。

math_errhandling更多细节。

二次

#include <iostream> #include <cfenv> #include <cmath> #pragma STDC FENV_ACCESS ON volatile double zero = 0.0; // volatile not needed where FENV_ACCESS is supported volatile double one = 1.0; // volatile not needed where FENV_ACCESS is supported int main() { std::feclearexcept(FE_ALL_EXCEPT std::cout << "1.0/0.0 = " << 1.0 / zero << '\n'; if(std::fetestexcept(FE_DIVBYZERO)) { std::cout << "division by zero reported\n"; } else { std::cout << "divsion by zero not reported\n"; } std::feclearexcept(FE_ALL_EXCEPT std::cout << "1.0/10 = " << one/10 << '\n'; if(std::fetestexcept(FE_INEXACT)) { std::cout << "inexact result reported\n"; } else { std::cout << "inexact result not reported\n"; } std::feclearexcept(FE_ALL_EXCEPT std::cout << "sqrt(-1) = " << std::sqrt(-1) << '\n'; if(std::fetestexcept(FE_INVALID)) { std::cout << "invalid result reported\n"; } else { std::cout << "invalid result not reported\n"; } }

二次

产出:

二次

1.0/0.0 = inf division by zero reported 1.0/10 = 0.1 inexact result reported sqrt(-1) = -nan invalid result reported

二次

另见

math_errhandlingMATH_ERRNOMATH_ERREXCEPT (C++11)(C++11)(C++11)defines the error handling mechanism used by the common mathematical functions (macro constant)

浮点异常宏的C文档

© cppreference.com

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

http://en.cppreference.com/w/cpp/NUMERE/FINV/FE[医]例外