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值。

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

技术教程推荐

白话法律42讲 -〔周甲徳〕

消息队列高手课 -〔李玥〕

Node.js开发实战 -〔杨浩〕

移动端自动化测试实战 -〔思寒〕

JavaScript核心原理解析 -〔周爱民〕

Selenium自动化测试实战 -〔郭宏志〕

张汉东的Rust实战课 -〔张汉东〕

手机摄影 -〔@随你们去〕

说透5G -〔杨四昌〕

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