isunordered()函数检查是否可以将第一个参数的值与第二个参数进行有意义的比较。如果第一个参数不能与第二个参数进行有意义的比较(即一个或两个都是NAN),则返回1,否则返回0。
bool isunordered(float x,float y); bool isunordered(double x,double y); bool isunordered(float x,float y); bool isunordered(Arithmetic x,Arithmetic y);
(x,y):我们要比较的值。
如果一个或两个的值为NAN,则返回1,否则返回0。
让我们看一个简单的例子,当x的值为NAN时。
链接:https://www.learnfk.comhttps://www.learnfk.com/c++/cpp-math-isunordered-function.html
来源:LearnFk无涯教程网
#include <iostream> #include<math.h> using namespace std; int main() { float x=sqrt(-2); float y=3.2; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isunordered(x,y) : "<<isunordered(x,y); return 0; }
输出:
Values of x and y are : nan,3.2 isunordered(x,y) : 1
在此的示例x的值为NAN。因此,该函数返回1。
让我们看一个简单的例子
#include <iostream> #include<math.h> using namespace std; int main() { float x=2.6; float y=3.2; cout<<"Values of x and y are : "<<x<<","<<y<<'\n'; cout<<"isunordered(x,y) : "<<isunordered(x,y); return 0; }
输出:
Values of x and y are : 2.6,3.2 isunordered(x,y) : 0
在此示例中,x和y都不是NAN。因此,该函数返回0值。
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)