Compartilhar via


Not a Number (NAN) Items

The Visual C++ compiler supports comparisons of not a number (NAN) items in an IEEE-compliant manner. If x is NAN and y is not NAN:

  • (x != x) == true

  • (x == x) == false

  • (y > x) == false

  • (y < x) == false

NAN ordering tests always return false: NAN [<, <=, >, >=] [any_number] will be false.

The following code shows how NANs in Visual C++ cannot be compared successfully to a floating-point number:

#include <math.h>
#include <stdio.h>
#include <float.h>

int main( void ) {
unsigned long nan[2]={0xffffffff, 0x7fffffff};
double g = *( double* )nan;

if ( g <= 3.0 )
   printf( "g( %g ) <= 3.0\n", g );
else if ( g > 3.0)
   printf( "g( %g ) > 3.0\n", g );
else
   printf( "g( %g ) is NaN\n", g );
}

See Also

Reference

Lexical Conventions