FP_NORMAL, FP_SUBNORMAL, FP_ZERO, FP_INFINITE, FP_NAN
From cppreference.net
C++
Numerics library
| 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 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Common mathematical functions
| Nearest integer floating point operations | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Floating point manipulation functions | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| Classification and comparison | |||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||
| Types | |||||||||||||||||||||||||||||||||||||||||
| Macro constants | |||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
|
定义于头文件
<cmath>
|
||
|
#define FP_NORMAL /* 由实现定义 */
|
(C++11 起) | |
|
#define FP_SUBNORMAL /* 由实现定义 */
|
(C++11 起) | |
|
#define FP_ZERO /* 由实现定义 */
|
(C++11 起) | |
|
#define FP_INFINITE /* 由实现定义 */
|
(C++11 起) | |
|
#define FP_NAN /* 由实现定义 */
|
(C++11 起) | |
FP_NORMAL
、
FP_SUBNORMAL
、
FP_ZERO
、
FP_INFINITE
、
FP_NAN
宏分别表示不同类别的浮点数。它们均展开为整型常量表达式。
| 常量 | 说明 |
FP_NORMAL
|
表示该值为 规约形式 ,即不是无穷大、非规约形式、非数字或零 |
FP_SUBNORMAL
|
表示该值为 非规约形式 |
FP_ZERO
|
表示该值为正零或负零 |
FP_INFINITE
|
表示该值无法用底层类型表示(正无穷或负无穷) |
FP_NAN
|
表示该值为非数字(NaN) |
示例
运行此代码
#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 文档
关于
FP_categories
|
|