FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW, FE_ALL_EXCEPT
来自cppreference.com
![]() |
该页由英文版wiki使用Google Translate机器翻译而来。
该翻译可能存在错误或用词不当。鼠标停留在文本上可以看到原版本。你可以帮助我们修正错误或改进翻译。参见说明请点击这里. |
在头文件 <cfenv> 中定义
|
||
#define FE_DIVBYZERO /*implementation defined power of 2*/ |
(C++11 起) | |
#define FE_INEXACT /*implementation defined power of 2*/ |
(C++11 起) | |
#define FE_INVALID /*implementation defined power of 2*/ |
(C++11 起) | |
#define FE_OVERFLOW /*implementation defined power of 2*/ |
(C++11 起) | |
#define FE_UNDERFLOW /*implementation defined power of 2*/ |
(C++11 起) | |
#define FE_ALL_EXCEPT FE_DIVBYZERO | FE_INEXACT | \ FE_INVALID | FE_OVERFLOW | \ |
(C++11 起) | |
所有这些宏观常数(除FE_ALL_EXCEPT)扩大到整数常量表达式是不同的2的幂,唯一地标识所有受支持的浮点异常。每个宏定义,如果它支持.
原文:
All these macro constants (except FE_ALL_EXCEPT) expand to integer constant expressions that are distinct powers of 2, which uniquely identify all supported floating-point exceptions. Each macro is only defined if it is supported.
宏常数FE_ALL_EXCEPT,扩展位或所有其他
FE_*
,始终定义是零,如果不支持浮点异常的实施.原文:
The macro constant FE_ALL_EXCEPT, which expands to the bitwise OR of all other
FE_*
, is always defined and is zero if floating-point exceptions are not supported by the implementation. 常数
|
Explanation |
FE_DIVBYZERO
|
(以较早者为准)浮点运算过程中发生被零除
原文: division by zero occurred during the earlier floating-point operation |
FE_INEXACT
|
不精确的结果:,四舍五入是必要的存储(以较早者为准)浮点运算的结果
原文: inexact result: rounding was necessary to store the result of the earlier floating-point operation |
FE_INVALID
|
无效的操作:(以较早者为准)浮点运算,无法执行
原文: invalid operation: the earlier floating-point operation could not performed |
FE_OVERFLOW
|
早期的浮点运算的结果是太大,无法表示的
原文: the result of the earlier floating-point operation was too large to be representable |
FE_UNDERFLOW
|
(以较早者为准)浮点运算的结果是低于正常值
原文: the result of the earlier floating-point operation was subnormal |
FE_ALL_EXCEPT
|
按位或(OR)的所有受支持的浮点异常
原文: bitwise OR of all supported floating-point exceptions |
实现可以定义额外的宏常量
<cfenv>
,以确定额外的浮点异常。所有这些常量开始FE_
,然后由至少一个大写字母.原文:
The implementation may define additional macro constants in
<cfenv>
to identify additional floating-point exceptions. All such constants begin with FE_
followed by at least one uppercase letter.[编辑] 示例
#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
[编辑] 另请参阅
(C++11) (C++11) (C++11) |
使用常见的数学函数定义的错误处理机制 原文: defines the error handling mechanism used by the common mathematical functions (常量宏) |