C++ Math isunordered
The isunordered function determines if the first argument can be compared with the second argument. If either value is NaN or if the comparison is not meaningful, it returns 1; otherwise, it returns 0.
Syntax
Consider two numerical values 'x' and 'y'. The syntax format is as follows:
bool isunordered(float x,float y);
bool isunordered(double x,double y);
bool isunordered(float x,float y);
bool isunordered(Arithmetic x,Arithmetic y);
Parameter
(x,y) :The values which we want to compare.
Return value
If either one or both values are NaN, the function will return 1; otherwise, it will return 0.
Example 1
Let's examine a basic scenario where the value of x is not a number (NAN).
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=sqrt(-2);
float y=3.2;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isunordered(x,y) : "<<isunordered(x,y);
return 0;
}
Output:
Values of x and y are : nan,3.2
isunordered(x,y) : 1
In this instance, the variable x is NaN. As a result, the method will output a value of 1.
Example 2
Let's see a simple example
#include <iostream>
#include<math.h>
using namespace std;
int main()
{
float x=2.6;
float y=3.2;
cout<<"Values of x and y are : "<<x<<","<<y<<'\n';
cout<<"isunordered(x,y) : "<<isunordered(x,y);
return 0;
}
Output:
Values of x and y are : 2.6,3.2
isunordered(x,y) : 0
In this instance, both x and y do not have a value of NAN. As a result, the function will output a value of 0.