std:: fpclassify
| Common mathematical functions | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical special functions (C++17) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Mathematical constants (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Basic linear algebra algorithms (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Data-parallel types (SIMD) (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Floating-point environment (C++11) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Complex numbers | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Numeric array ( 
                valarray
               ) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Pseudo-random number generation | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Bit manipulation (C++20) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Saturation arithmetic (C++26) | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Factor operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Interpolations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Generic numeric operations | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | 
 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| C-style checked integer arithmetic | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 
 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Nearest integer floating point operations | |||||||||||||||||||||||||||||||||||||||||
| 
 | 
 | ||||||||||||||||||||||||||||||||||||||||
| Floating point manipulation functions | |||||||||||||||||||||||||||||||||||||||||
| 
 | 
 | ||||||||||||||||||||||||||||||||||||||||
| Classification and comparison | |||||||||||||||||||||||||||||||||||||||||
| 
 | |||||||||||||||||||||||||||||||||||||||||
| Types | |||||||||||||||||||||||||||||||||||||||||
| Macro constants | |||||||||||||||||||||||||||||||||||||||||
| 
 | 
 | ||||||||||||||||||||||||||||||||||||||||
| 
           定义于头文件
            
            
             <cmath>
            
            | ||
| (1) | ||
| 
           
           
           
            
             int
            
            fpclassify
            
             (
            
            
             float
            
            num
            
             )
            
            
             ;
            
             
             
              int
             
             fpclassify
             
              (
             
             
              double
             
             num
             
              )
             
             
              ;
             
              | (C++11 起) (C++23 前) | |
| 
           
            
             constexpr
            
            
             int
            
            fpclassify
            
             (
            
            
             /* 浮点类型 */
            
            num
            
             )
            
            
             ;
            
           
           | (C++23 起) | |
| 
           定义于头文件
            
            
             <cmath>
            
            | ||
| 
           
            
             template
            
            
             <
            
            
             class
            
            Integer
            
             >
            
             int fpclassify ( Integer num ) ; | (A) | (C++11 起) (C++23 起为 constexpr) | 
          std::fpclassify
         
         的重载,作为参数
         
          
           num
          
         
         的类型。
        
        
         
          (since C++23)
         
        
       
      | 目录 | 
参数
| num | - | 浮点数或整数值 | 
返回值
以下之一: FP_INFINITE 、 FP_NAN 、 FP_NORMAL 、 FP_SUBNORMAL 、 FP_ZERO 或实现定义的类型,用于指定 num 的类别。
注释
额外的重载不需要完全按照 (A) 的形式提供。只需确保对于整数类型的实参 num , std :: fpclassify ( num ) 与 std :: fpclassify ( static_cast < double > ( num ) ) 具有相同效果即可。
示例
#include <cfloat> #include <cmath> #include <iostream> auto show_classification(double x) { switch (std::fpclassify(x)) { case FP_INFINITE: return "Inf"; case FP_NAN: return "NaN"; case FP_NORMAL: return "normal"; case FP_SUBNORMAL: return "subnormal"; case FP_ZERO: return "zero"; default: return "unknown"; } } int main() { std::cout << "1.0/0.0 is " << show_classification(1 / 0.0) << '\n' << "0.0/0.0 is " << show_classification(0.0 / 0.0) << '\n' << "DBL_MIN/2 is " << show_classification(DBL_MIN / 2) << '\n' << "-0.0 is " << show_classification(-0.0) << '\n' << "1.0 is " << show_classification(1.0) << '\n'; }
输出:
1.0/0.0 is Inf 0.0/0.0 is NaN DBL_MIN/2 is subnormal -0.0 is zero 1.0 is normal
参见
| 
           
            
             
              (C++11)
             
            
           
           | 检查给定数值是否为有限值 (函数) | 
| 
           
            
             
              (C++11)
             
            
           
           | 检查给定数值是否为无穷大 (函数) | 
| 
           
            
             
              (C++11)
             
            
           
           | 检查给定数值是否为 NaN (函数) | 
| 
           
            
             
              (C++11)
             
            
           
           | 检查给定数值是否正规 (函数) | 
| 提供查询所有基础数值类型属性的接口 (类模板) | |
| 
          
           
            C 文档
           
          
          for
          
           
            fpclassify
           
          
          | |