详解C++中的isunordered函数

时间:2022-06-07 12:23:35

所述isunordered()函数定义在<cmath.h>并检查是否第一个参数的值可以有意义与第二个参数进行比较。如果第一个参数不能与第二个参数进行有意义的比较(即一个或两个都是NAN),则返回1,否则返回0。

句法:

bool isunordered(float x,float y);

或者

bool是无序的(double x,double y);

参数:它使用两个值x和y,即用于检查它们是否无序的值。

返回:它返回1,如果x或y值是NAN,否则返回0。

下面的程序说明了C ++中的isunordered()函数:

示例一:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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;
 
 cout<<"isunordered(x, y) = "<<isunordered(x, y);
 
 return 0;
 
}

输出:

x的值是6.3

y的值是= -nan

isunordered(x,y)= 1

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

示例2:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#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;
 
 cout<<"isunordered(x, y) = "<<isunordered(x, y);
 
 return 0;
 
}

输出:

x的值是4.6

y的值是9.2

isunordered(x,y)= 0

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

到此这篇关于详解C++中的isunordered函数的文章就介绍到这了,更多相关C++ isunordered函数内容请搜索服务器之家以前的文章或继续浏览下面的相关文章希望大家以后多多支持服务器之家!

原文链接:https://www.cnblogs.com/258a/archive/2021/03/17/14551445.html