FE_DIVBYZERO, FE_INEXACT, FE_INVALID, FE_OVERFLOW, FE_UNDERFLOW, FE_ALL_EXCEPT
      From cppreference.net
     
     
     | 
           定义于头文件
            
            
             <cfenv>
            
            | ||
| 
           
            
             #define FE_DIVBYZERO    /*由实现定义的2的幂次*/
            
           
           | (C++11 起) | |
| 
           
            
             #define FE_INEXACT      /*由实现定义的2的幂次*/
            
           
           | (C++11 起) | |
| 
           
            
             #define FE_INVALID      /*由实现定义的2的幂次*/
            
           
           | (C++11 起) | |
| 
           
            
             #define FE_OVERFLOW     /*由实现定义的2的幂次*/
            
           
           | (C++11 起) | |
| 
           
            
             #define FE_UNDERFLOW    /*由实现定义的2的幂次*/
            
           
           | (C++11 起) | |
| 
           
            
             #define FE_ALL_EXCEPT   FE_DIVBYZERO | FE_INEXACT | \
              
              FE_INVALID | FE_OVERFLOW |  \
               | (C++11 起) | |
       所有这些宏常量(除
       
        FE_ALL_EXCEPT
       
       外)都展开为不同的2的幂次整数常量表达式,这些表达式能唯一标识所有支持的浮点异常。每个宏仅在其受支持时才会被定义。
      
       宏常量
       
        FE_ALL_EXCEPT
       
       (展开为所有其他
       
        FE_*
       
       宏的按位或运算结果)始终被定义,若实现不支持浮点异常则其值为零。
      
| 常量 | 说明 | 
| 
          FE_DIVBYZERO
          | 先前浮点运算中出现了极点错误 | 
| 
          FE_INEXACT
          | 不精确结果:存储先前浮点运算结果时需要舍入 | 
| 
          FE_INVALID
          | 先前浮点运算中出现了定义域错误 | 
| 
          FE_OVERFLOW
          | 先前浮点运算结果超出可表示范围 | 
| 
          FE_UNDERFLOW
          | 先前浮点运算结果为次正规数并存在精度损失 | 
| 
          FE_ALL_EXCEPT
          | 所有支持的浮点异常的按位或运算 | 
       实现可以在
       
        
         <cfenv>
        
       
       中定义额外的宏常量来标识附加的浮点异常。所有此类常量均以
       
        FE_
       
       开头,后跟至少一个大写字母。
      
有关详细信息,请参阅 math_errhandling 。
示例
         运行此代码
        
       #include <cfenv> #include <cmath> #include <iostream> // #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 << "division 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)
             
            
           
           | 定义通用数学函数使用的错误处理机制 (宏常量) | 
| 
          
           
            C 文档
           
          
          关于
          
           
            浮点异常宏
           
          
          | |