FE_DFL_ENV
铁[医]DFL[医]环境变化
Defined in header | | |
---|---|---|
#define FE_DFL_ENV /*implementation defined*/ | | (since C++11) |
宏常数FE_DFL_ENV
展开为类型的表达式。const std::fenv_t*
指向默认浮点环境的完整副本,即程序启动时加载的环境。
其他宏,以FE_
后面跟着大写字母,并有类型const std::fenv_t*
,可以由实现来支持。
例
二次
#include <iostream>
#include <cfenv>
#pragma STDC FENV_ACCESS ON
void show_env()
{
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";
int r = std::fegetround(
switch(r)
{
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
二次
另见
fegetenvfesetenv (C++11) | saves or restores the current floating point environment (function) |
---|---|
feupdateenv (C++11) | restores the floating-point environment and raises the previously raise exceptions (function) |
© cppreference.com
在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。
http://en.cppreference.com/w/cpp/NUMERE/FINV/FE[医]DFL[医]环境变化