📅  最后修改于: 2020-10-19 00:22:09             🧑  作者: Mango
该函数检查数字是否为非数字。如果数字为NaN,则返回1,否则返回0。
注意:对于浮点元素,例如负数的平方根或0/0的结果,NaN是不可表示的值。
假设数字是“ x”。语法为:
bool isnan(float x);
bool isnan(double x);
bool isnan(long double x);
bool isnan(integral x);
×:是浮点值。
如果x为NAN,则返回1,否则返回0。
让我们看一个简单的例子,当x的值为0.0 / 0.0时。
#include
#include
using namespace std;
int main()
{
float x=0.0/0.0;
cout<<"value of x is : "<
输出:
value of x is : -nan
isnan(x) : 1
在此示例中,isnan(x)确定x的值为nan。因此,它返回1。
让我们看一下x值为4.3时的简单示例。
#include
#include
using namespace std;
int main()
{
float x=4.3;
cout<<"value of x is : "<
输出:
value of x is : 4.3
isnan(x) : 0
在此示例中,isnan(x)函数确定x的值不是’nan’。因此,它返回0值。