Possible Duplicates:
Objective C - float checking for nan
Determine if NSNumber is NaN可能的重复:Objective C - float check for nan确定NSNumber是否为nan
I have a problem with NaN values in CGFloat, how can I check if the number is valid?
我在CGFloat中有一个NaN值的问题,我如何检查这个数字是否有效?
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 ...
这根本不是一个好的解决方案!!!:)……我很确定我还应该做些别的事情……
1 个解决方案
#1
138
There is a define for checking if a number is nan inf etc in math.h (you can use it without import I think).
在数学中,有一个定义来检查一个数字是否为nan inf等。h(我认为你可以不用进口就能使用它)。
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 , ...
也有一些其他有用的定义,如:伊希夫,isnormal, is限性,…
#1
138
There is a define for checking if a number is nan inf etc in math.h (you can use it without import I think).
在数学中,有一个定义来检查一个数字是否为nan inf等。h(我认为你可以不用进口就能使用它)。
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 , ...
也有一些其他有用的定义,如:伊希夫,isnormal, is限性,…