isunordered() function in C++

The isunordered() function is defined in <cmath.h> and checks whether the value of first argument can be meaningfully compared with the second argument. If the first argument cannot be meaningfully compared with the second argument (i.e one or both are NAN), it return 1 otherwise 0.

Syntax:

bool isunordered(float x, float y);

or

bool isunordered(double x, double y);

Parameters: It takes two values x and y i.e values to check whether they are unordered.

Returns: It returns 1 if the value of x or y are NAN, Otherwise it returns 0.

Below programs illustrate the isunordered() function in C++:

Example 1:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of isunordered() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  float x=6.3;
  float y=sqrt(-9);
  
  cout<<"The value of x is= "<< x << endl;
  cout<<"The value of y is= "<< y << endl;
  
  //Now it return whether x or y are unordered values or not
  cout<<"isunordered(x, y) = "<<isunordered(x, y);
  return 0;
}

chevron_right


Output:

The value of x is= 6.3
The value of y is= -nan
isunordered(x, y) = 1

Explanation: In the example 1 the value of y is NAN thats why function returns 1.

Example 2:-

filter_none

edit
close

play_arrow

link
brightness_4
code

// c++ program to demonstrate
// example of isunordered() function.
  
#include <bits/stdc++.h>
using namespace std;
  
int main()
{
  float x=4.6;
  float y=9.2;
  
  cout<<"The value of x is= "<< x << endl;
  cout<<"The value of y is= "<< y << endl;
  
  //Now it return whether x or y are unordered values or not
  cout<<"isunordered(x, y) = "<<isunordered(x, y);
  return 0;
}

chevron_right


Output:

The value of x is= 4.6
The value of y is= 9.2
isunordered(x, y) = 0

Explanation: In the example 2 the value of x and y are not NAN thats why the function returns 0.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.