C++中的ISUNORDED()函数

这个 是无序的 函数在中定义 并检查第一个参数的值是否可以与第二个参数进行有意义的比较。如果第一个参数无法与第二个参数进行有意义的比较(即一个或两个参数均为NAN),则返回1,否则返回0。

null

语法:

bool isunordered(float x, float y);

bool isunordered(double x, double y);

参数: 需要 两个值x和y i、 e值以检查它们是否无序。

返回: 它回来了 1. 如果x或y的值为NAN,则返回NAN 0 .

下面的程序演示了C++中的isunordered()函数:

例1:-

// c++ program to demonstrate
// example of isunordered() function.
#include <bits/stdc++.h>
using namespace std;
int main()
{
float x=6.3;
float y= sqrt (-9);
cout<< "The value of x is= " << x << endl;
cout<< "The value of y is= " << y << endl;
//Now it return whether x or y are unordered values or not
cout<< "isunordered(x, y) = " <<isunordered(x, y);
return 0;
}


输出:

The value of x is= 6.3
The value of y is= -nan
isunordered(x, y) = 1

说明: 在示例1中,y的值为NAN,这就是函数返回1的原因。

例2:-

// c++ program to demonstrate
// example of isunordered() function.
#include <bits/stdc++.h>
using namespace std;
int main()
{
float x=4.6;
float y=9.2;
cout<< "The value of x is= " << x << endl;
cout<< "The value of y is= " << y << endl;
//Now it return whether x or y are unordered values or not
cout<< "isunordered(x, y) = " <<isunordered(x, y);
return 0;
}


输出:

The value of x is= 4.6
The value of y is= 9.2
isunordered(x, y) = 0

说明: 在示例2中,x和y的值不是NAN,这就是函数返回0的原因。

© 版权声明
THE END
喜欢就支持一下吧
点赞5 分享