C Data Type Functions - C isunordered






Returns whether x or y are unordered values.

Prototype C99

The C99 prototype is listed as follows.

macro isunordered(x,y) 
        

Prototype C++11

The C++11 prototype is listed as follows.

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

Parameter

This function has the following parameter.

x, y
Values to check whether they are unordered.

Return

true 1 if either x or y is NaN. false 0 otherwise.

Example


#include <stdio.h> /* printf */
#include <math.h> /* isunordered, sqrt */
/*w  w w.  ja  v a  2s .  com*/
int main (){
  double result;
  result = sqrt (-1.0);

  if (isunordered(result,0.0))
    printf ("sqrt(-1.0) and 0.0 cannot be ordered");
  else
    printf ("sqrt(-1.0) and 0.0 can be ordered");

  return 0;
} 

       

The code above generates the following result.





Example 2


#include <stdio.h>
#include <math.h>
 /* w ww .  ja  v  a 2 s .  com*/
int main(void){
    printf("isunordered(NAN,1.0) = %d\n", isunordered(NAN,1.0));
    printf("isunordered(1.0,NAN) = %d\n", isunordered(1.0,NAN));
    printf("isunordered(NAN,NAN) = %d\n", isunordered(NAN,NAN));
    printf("isunordered(1.0,0.0) = %d\n", isunordered(1.0,0.0));
 
    return 0;
}

The code above generates the following result.