FE_DFL_ENV
来自 cppreference.cn
定义于头文件 <cfenv> |
||
#define FE_DFL_ENV /*实现定义*/ |
(C++11 起) | |
宏常量 FE_DFL_ENV
展开为类型为 const std::fenv_t* 的表达式,它指向默认浮点环境的完整副本,即程序启动时加载的环境。
以 FE_
开头后跟大写字母且类型为 const std::fenv_t* 的其他宏,可能受到实现支持。
[编辑] 示例
运行此代码
#include <cfenv> #include <iostream> // #pragma STDC FENV_ACCESS ON void show_env() { const int e = std::fetestexcept(FE_ALL_EXCEPT); if (e & FE_DIVBYZERO) std::cout << "division by zero is raised\n"; if (e & FE_INEXACT) std::cout << "inexact is raised\n"; if (e & FE_INVALID) std::cout << "invalid is raised\n"; if (e & FE_UNDERFLOW) std::cout << "underflow is raised\n"; if (e & FE_OVERFLOW) std::cout << "overflow is raised\n"; switch (std::fegetround()) { case FE_DOWNWARD: std::cout << "rounding down\n"; break; case FE_TONEAREST: std::cout << "rounding to nearest\n"; break; case FE_TOWARDZERO: std::cout << "rounding to zero\n"; break; case FE_UPWARD: std::cout << "rounding up\n"; break; } } int main() { std::cout << "On startup:\n"; show_env(); std::feraiseexcept(FE_UNDERFLOW | FE_OVERFLOW); std::fesetround(FE_UPWARD); std::cout << "\nBefore restoration:\n"; show_env(); std::fesetenv(FE_DFL_ENV); std::cout << "\nAfter reset to default:\n"; show_env(); }
输出
On startup: rounding to nearest Before restoration: underflow is raised overflow is raised rounding up After reset to default: rounding to nearest
[编辑] 参见
(C++11) |
保存或恢复当前浮点环境 (函数) |
(C++11) |
恢复浮点环境并引发先前引发的异常 (函数) |
C 文档 关于 FE_DFL_ENV
|