C++ Standard Library C++ STL Library

C++ <cmath> - isunordered() Function



The C++ <cmath> isunordered() function returns true if one or both arguments are unordered value, else returns false. If one or both arguments are NaN, the arguments are unordered and thus cannot be meaningfully compared with each other.

Syntax

bool isunordered (float x, float y);
bool isunordered (double x, double y);
bool isunordered (long double x, long double y);               

Parameters

x Specify first floating point value.
y Specify second floating point value.

Return Value

Returns true (1) if one or both arguments are NaN, else returns false (0).

Example:

The example below shows the usage of isunordered() function.

#include <iostream>
#include <cmath>
using namespace std;
 
int main (){

  cout<<boolalpha;
  cout<<"isunordered(1.0, 2.0): "<<isunordered(1.0, 2.0)<<"\n";
  cout<<"isunordered(1.0, 1.0/0.0): "<<isunordered(1.0, 1.0/0.0)<<"\n";
  cout<<"isunordered(1.0, 0.0/0.0): "<<isunordered(1.0, 0.0/0.0)<<"\n";
  cout<<"isunordered(1.0, sqrt(-1.0)): "<<isunordered(1.0, sqrt(-1.0))<<"\n";
  return 0;
}

The output of the above code will be:

isunordered(1.0, 2.0): false
isunordered(1.0, 1.0/0.0): false
isunordered(1.0, 0.0/0.0): true
isunordered(1.0, sqrt(-1.0)): true

❮ C++ <cmath> Library

5