Math Isunordered Function

C++ Math isunordered

The isunordered function 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

Consider two numbers 'x' and 'y'. Syntax would be:

Example

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 the value of one or both are NAN then it returns 1, otherwise 0.

Example 1

Let's see a simple example when the value of x is NAN.

Example

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

Output

Values of x and y are : nan,3.2
isunordered(x,y) : 1

In this example, the value of x is NAN. Therefore, the function returns 1.

Example 2

Let's see a simple example

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:

Output

Values of x and y are : 2.6,3.2
isunordered(x,y) : 0

In this example, both x and y are not NAN. Therefore, the function returns 0 value.

Input Required

This code uses input(). Please provide values below: