isunordered(x,y)函数详解

首页 / C++入门教程 / isunordered(x,y)函数详解

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

isunordered - 语法

bool isunordered(float x,float y);
bool isunordered(double x,double y);
bool isunordered(float x,float y);
bool isunordered(Arithmetic x,Arithmetic y);

isunordered - 参数

(x,y):我们要比较的值。

isunordered - 返回值

如果一个或两个的值为NAN,则返回1,否则返回0。

isunordered - 例子1

让我们看一个简单的例子,当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。

isunordered - 例子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值。

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

深入浅出gRPC -〔李林锋〕

零基础学Java -〔臧萌〕

透视HTTP协议 -〔罗剑锋(Chrono)〕

研发效率破局之道 -〔葛俊〕

Netty源码剖析与实战 -〔傅健〕

用户体验设计实战课 -〔相辉〕

Python自动化办公实战课 -〔尹会生〕

说透5G -〔杨四昌〕

陈天 · Rust 编程第一课 -〔陈天〕

好记忆不如烂笔头。留下您的足迹吧 :)