isunordered() function in C++


In this article we are going to discuss the isunordered() function in C++, its syntax, working and its return values.

isunordered() function is an inbuilt function in C++ which is defined in header file. The function checks whether the two floating points number be NAN, if both or either one of them is NAN then it will return 1(true) else will return 0(false).

Syntax

bool isunordered(float n1, float n2);

or

bool isunordered(double n1, double n2);

or

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

The function accepts two floating point variables to compare and check if either one of these is nan.

Return value

The function return the boolean value i.e., 1 for true and 0 for false.

Example

 Live Demo

#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
}

Output

If we run the above code it will generate the following output −

-nan
1

Example

 Live Demo

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

Output

If we run the above code it will generate the following output −

0

Updated on: 28-Feb-2020

26 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements