C++ 中的 isunordered() 函数


在本文中,我们将讨论 C++ 中的 isunordered() 函数及其语法、工作原理和返回值。

isunordered() 函数是 C++ 中一个已有的函数,定义于头文件。该函数检查两个浮点数是否为 NAN,如果两者或其中一个为 NAN,则返回 1(真),否则返回 0(假)。

语法

bool isunordered(float n1, float n2);

bool isunordered(double n1, double n2);

bool isunordered(long double n1, long double n2);

该函数接受两个浮点变量进行比较,并检查其中是否有一个是 nan。

返回值

该函数返回布尔值,即真为 1,假为 0。

示例

 实时演示

#include <iostream>
#include <cmath>
using namespace std;
int main() {
   float a = -1.0;
   float c = sqrt(-1.0);
   cout<<c;
   //printing the result of c
   cout<<"\n"<<isunordered(c, 0.0); //will check if either of them is nan
}

输出

如果我们运行以上代码,它将生成以下输出 -

-nan
1

示例

 实时演示

#include <iostream>
#include <cmath>
using namespace std;
int main() {
   cout<<isunordered(0.0, -1.0);
}

输出

如果我们运行以上代码,它将生成以下输出 -

0

更新于:2020 年 2 月 28 日

30 次浏览

开启你的 职业生涯

完成课程,获得认证

开始
广告
© . All rights reserved.