Last Updated: Mar 27, 2024
Difficulty: Easy

# isunordered() function in C++

Leveraging ChatGPT - GenAI as a Microsoft Data Expert
Speaker
Prerita Agarwal
Data Specialist @
23 Jul, 2024 @ 01:30 PM

## Introduction

The value of the first argument is meaningfully checked with the second argument by the isunordered() function. If the first argument can not be compared with the second argument, the program will return 1; otherwise, 0. The isunordered() function is a library function in the header file cmath and checks whether the given values are unordered, i.e., if one or both values are Not-A-Number (NaN).

Parameters: It will take two values, x, and y, i.e., the values, to check whether they are unordered or not.

Returns: It will return 1 when the value of x or y is NAN. Otherwise, it will return 0.

### Syntax

``````bool isunordered(float x, float y)
bool isunordered(double x, double y)``````

The isunordered() function will take two values as input and test if they are unordered or not. It returns 1 if either or both of the two values is NAN, or else it returns 0.

Also see, Literals in C, Fibonacci Series in C++

## Example

### Code

``````#include <iostream>
#include <cmath>
using namespace std;
int main()
{
float x = 12.0;
float y = sqrt(-12.0);

cout << "x is " << x << endl;
cout << "y is " << y << endl;

if(isunordered(x, y) == 1)
{
cout << "x and y are unordered\n";
}
else
{
cout << "x and y are not unordered\n";
}
return 0;
}``````

### Output

``````x is 12
y is -nan
x and y are unordered``````

### Explanation

The isunordered() function takes two values x and y where x= 12.0 and y=sqrt(-12.0) as input and tests if they are unordered. It returns 1 if either or both of the two values is NAN otherwise it returns 0.

Try and compile with online c++ compiler.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

## Example 2

### Code

``````#include <iostream>
#include <cmath>
using namespace std;
int main()
{
double x = 12.0;
double y = -12.0;

cout << "x is " << x << endl;
cout << "y is " << y << endl;

if(isunordered(x, y) == 1)
{
cout << "x and y are unordered\n";
}
else
{
cout << "x and y are not unordered\n";
}
return 0;
}``````

### Output

``````x is 12
y is -12
x and y are not unordered``````

### Explanation

The isunordered() function takes two values x and y where x= 12.0 and y= -12.0 as input and tests if they are unordered. It returns 1 if either or both of the two values is NAN otherwise it returns 0.

#### What is isunordered() function?

The isunordered() function is a library function in the header file cmath and checks whether the given values are unordered, i.e., if one or both values are Not-A-Number (NaN).

#### Where is the isunordered() function defined?

The isunordered() function is a function in C++ defined in the cmath header file.

#### What does isunordered() function returns?

It will return 1 when the value of x or y is NAN. Otherwise, it will return 0.

## Conclusion

This article extensively discussed the C++ Program for isunordered() function. We hope that this blog has helped you gain more knowledge regarding isunordered() and other functions, check out our articles on Coding Ninjas.

Refer to our Guided Path on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But if you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc.; you must look at the problemsinterview experiences, and interview bundle for placement preparations.

Nevertheless, you may consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Happy Learning!

Topics covered
1.
Introduction
1.1.
Syntax
2.
Example
2.1.
Code
2.2.
Output
2.3.
Explanation
3.
Example 2
3.1.
Code
3.2.
Output
3.3.
Explanation
4.