Objective-C: int can´t be NAN?

It seems that a int in Objective-C can't be NAN. This comparision returns false.

int i = NAN;
NSLog(@"isNan: %@", (isnan(i)) ? @"YES" : @"NO");

Is there any way to set an int to NAN, or do i have to use a double?

double d = NAN;
NSLog(@"isNan: %@", (isnan(d)) ? @"YES" : @"NO");

With a double it works.


NaN is a value that is specific to the way that floating point numbers (float and double in C) are represented internally (IEEE 754). Is is not available for integer data types, as they may be represented in a completely different manner.

As a workaround, you may see people use a separate boolean flag to indicate if a value is valid, or the extreme values INT_MIN/INT_MAX. Although, nether of these is as good as NaN for ensuring valid values.

Need Your Help

Programmatically turn off the screen partially in android

android screen

Is it possible to turn off the screen partially in android phones (while keeping other part active)? Using NDK? Does anyone have experience doing it?

Mapping line numbers across two diff files using emacs/python/winmerge

python emacs diff winmerge

Consider the following two files that are slightly different: