📅  最后修改于: 2020-10-19 00:22:43             🧑  作者: Mango
该函数根据x的值返回与宏常量之一匹配的int类型的值。
value | description |
---|---|
FP_INFINITE | Positive or negative infinity |
FP_NAN | Not a Number |
FP_ZERO | Value of zero. |
FP_SUBNORMAL | Sub Normal value |
FP_NORMAL | Normal value |
假设数字是x。语法为:
int fpclassify(float x);
int fpclassify(double x);
int fpclassify(long double x);
int fpclassify(int x);
x:与宏常量之一匹配的值。
它返回以下整数值:FP_INFINITE,FP_NAN,FP_ZERO,FP_SUBNORMAL和FP_NORMAL。
让我们看一个简单的例子。
#include
#include
using namespace std;
int main()
{
double d=1.0/0.0;
switch(fpclassify(d))
{
case FP_INFINITE:
cout<<"1.0/0.0 is a infinite number ";
break;
case FP_NAN:
cout<<"1.0/0.0 is Not a Number";
break;
case FP_ZERO:
cout<<"1.0/0.0 is zero.";
break;
case FP_SUBNORMAL:
cout<<"1.0/0.0 is a subnormal value";
break;
case FP_NORMAL:
cout<<"1.0/0.0 is a normal value";
break;
default:
cout<<"wrong number";
}
return 0;
}
输出:
1.0/0.0 is a infinite number
在此示例中,fpclassify()函数确定x为无限数。