在线文档教程
C++
数字 | Numerics

std::fpclassify

STD::fpclass

Defined in header
int fpclassify( float arg (1)(since C++11)
int fpclassify( double arg (2)(since C++11)
int fpclassify( long double arg (3)(since C++11)
int fpclassify( Integral arg (4)(since C++11)

1-3%29对浮点数进行分类arg分为以下几类:零、次正规、正规、无限、NAN或实现定义范畴.

4%29一组重载或接受from任何论点积分型等效于%282%29%28的参数转换为double29%。

参数

arg-floating point value

返回值

其中之一FP_INFINITE,,,FP_NAN,,,FP_NORMAL,,,FP_SUBNORMAL,,,FP_ZERO或实现定义类型,指定arg...

二次

#include <iostream> #include <cmath> #include <cfloat> const char* 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

二次

另见

isfinite (C++11)checks if the given number has finite value (function)
isinf (C++11)checks if the given number is infinite (function)
isnan (C++11)checks if the given number is NaN (function)
isnormal (C++11)checks if the given number is normal (function)
numeric_limitsprovides an interface to query properties of all fundamental numeric types. (class template)

c fpclass的文档

© cppreference.com

在CreativeCommonsAttribution下授权-ShareAlike未移植许可v3.0。

http://en.cppreference.com/w/cpp/数值/数学/fpclass