How to check NaN value in Objective-C (iOS)

Possible duplicates:
Objective-C - float check for nan
Determine if NSNumber NaN

I have a problem with NaN values ​​in CGFloat, how can I check if the number is correct?

so far the only way that works:

if ([[NSString stringWithFormat:@"%f", output] isEqualToString:@"nan"]) { output = 0; } 

which is not a good solution at all! :) ... and I'm sure there is something else that I should do instead.

+45
ios objective-c iphone xcode cgfloat
Jun 02 2018-11-11T00:
source share
1 answer

There is a definition for checking if a number is nan inf, etc. in math.h (you can use it without import, I think).

 isnan(myValue) 

if you follow the definition that you get in

 (x!=x) 

there are other useful definitions like isinf, isnormal , isfinite , ...

+139
Jun 02 2018-11-11T00:
source share



All Articles