该函数检查数字是否为非数字。如果数字为NaN,则返回1,否则返回0。
假设数字是“ x”。语法为:
bool isnan(float x); bool isnan(double x); bool isnan(long double x); bool isnan(integral x);
x :这是一个浮点值。
如果x为NAN,则返回1,否则返回0。
让我们看一下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。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-isnan-function.html
来源:LearnFk无涯教程网
让我们看一下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值。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)