首页
学习
活动
专区
工具
TVP
发布
精选内容/技术社群/优惠产品,尽在小程序
立即前往

std::fpclassify

Defined in header <cmath>

?

?

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...

二次

代码语言:javascript
复制
#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';
}

二次

产出:

二次

代码语言:javascript
复制
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_limits

provides an interface to query properties of all fundamental numeric types. (class template)

c fpclass的文档

代码语言:txt
复制
 ? cppreference.com

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

扫码关注腾讯云开发者

领取腾讯云代金券

http://www.vxiaotou.com