C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Math isunordered()

C++ Math isunordered()

isunordered()函数检查是否可以将第一个参数的值与第二个参数进行有意义的比较。如果第一个参数不能与第二个参数进行有意义的比较(即一个或两个都是NAN),则返回1,否则返回0。

语法

考虑两个数字'x'和'y'。语法为:
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。

示例1

让我们看看x的值为NAN的简单示例。
#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、

示例2

让我们看一个简单的示例
#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值。

昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4