Table of contents
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.
Frequently Asked Questions
4.1.
What is isunordered() function?
4.2.
Where is the isunordered() function defined?
4.3.
What does isunordered() function returns?
5.
Conclusion
Last Updated: Mar 27, 2024
Easy

isunordered() function in C++

Author Ayushi Poddar
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

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.

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.

Frequently Asked Questions

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.

Recommended Readings:

 

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!

Live masterclass