C++ Math isnan()
C++ Math isnan()
该函数检查数字是否为非数字。如果数字为NaN,则返回1,否则返回0。
注意: NaN是浮点元素的不可表示的值,例如负数的平方根或0/0的结果。
语法
假设数字是" x"。语法为:
bool isnan(float x);
bool isnan(double x);
bool isnan(long double x);
bool isnan(integral x);
参数
x : 它是浮点值。
返回值
如果x为NAN,则返回1,否则返回0。
示例1
让我们看一下x值为0.0/0.0时的简单示例。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=0.0/0.0;
cout<<"value of x is : "<<x<<'\n';
cout<<"isnan(x) : "<<isnan(x);
return 0;
}
输出:
value of x is :-nan
isnan(x) : 1
在此示例中,isnan(x)确定x的值为nan。因此,它返回1、
示例2
让我们看一下x值为4.3时的简单示例。
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=4.3;
cout<<"value of x is : "<<x<<'\n';
cout<<"isnan(x) : "<<isnan(x);
return 0;
}
输出:
value of x is : 4.3
isnan(x) : 0
在此示例中,isnan(x)函数确定x的值不是'nan'。因此,它返回0值。