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.
NaNis a value that is specific to the way that floating point numbers (floatanddoublein 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 asNaNfor ensuring valid values.