C++ 中的 isunordered() 函数

c++server side programmingprogramming

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

isunordered() 函数是 C++ 中的一个内置函数,定义在头文件中。该函数检查两个浮点数是否为 NAN,如果两个或其中一个为 NAN,则返回 1 (true),否则返回 0 (false)。

语法

bool isunordered(float n1, float n2);

bool isunordered(double n1, double n2);

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

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

返回值

该函数返回布尔值,即 1 表示 true,0 表示 false。

示例

#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

相关文章