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

IosObjective CXcodeCgfloat

Ios Problem Overview


> Possible Duplicates:
> Objective-C - float checking for nan
> Determine if NSNumber is NaN

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

the only way so far that works is:

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

which is not a nice solution at all! :) ... and I am pretty sure that there is something else I should do instead.

Ios Solutions


Solution 1 - Ios

There is a define 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 define you will end up with

(x!=x)

there are also some other useful defines like isinf, isnormal , isfinite , ...

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionOndrej RafajView Question on Stackoverflow
Solution 1 - IosthomasView Answer on Stackoverflow