该函数根据x的值返回与宏常量之一匹配的int类型的值。
值 | 说明 |
---|---|
FP_INFINITE | 正无穷大或负无穷大 |
FP_NAN | 不是数字 |
FP_ZERO | 值为零。 |
FP_SUBNORMAL | Sub正常值 |
FP_NORMAL | 正常值 |
假设数字是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 <iostream> #include<math.h> 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为无限数。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)