命名空间
变体
操作

FE_DFL_ENV

来自 cppreference.com
< cpp‎ | numeric‎ | fenv
 
 
 
浮点环境
函数
(C++11)(C++11)
(C++11)(C++11)
宏常量
FE_DFL_ENV
(C++11)
 
定义在头文件 <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 文档 for FE_DFL_ENV