該函數返回與宏常量之一匹配的 int 類型值,具體取決於 x 的值。
值 | 描述 |
---|---|
FP_INFINITE | 正無窮大或負無窮大 |
FP_NAN | 不是數字 |
FP_ZERO | 值為零。 |
FP_SUBNORMAL | 亞正常值 |
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 是一個無限數。
相關用法
- C++ Math fabs()用法及代碼示例
- C++ Math fdim()用法及代碼示例
- C++ Math fma()用法及代碼示例
- C++ Math fmin()用法及代碼示例
- C++ Math frexp()用法及代碼示例
- C++ Math fmax()用法及代碼示例
- C++ Math floor()用法及代碼示例
- C++ Math fmod()用法及代碼示例
- C++ Math scalbn()用法及代碼示例
- C++ Math acosh()用法及代碼示例
- C++ Math asinh()用法及代碼示例
- C++ Math isgreater()用法及代碼示例
- C++ Math islessgreater()用法及代碼示例
- C++ Math log2()用法及代碼示例
- C++ Math nearbyint()用法及代碼示例
- C++ Math tan()用法及代碼示例
- C++ Math log()用法及代碼示例
- C++ Math nextafter()用法及代碼示例
- C++ Math isfinite()用法及代碼示例
- C++ Math erfc()用法及代碼示例
注:本文由純淨天空篩選整理自 C++ Math fpclassify()。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。