如何检查Objective-C中的NaN值(iphone sdk) [英] how to check for NaN value in Objective-C (iphone sdk)

查看:153
本文介绍了如何检查Objective-C中的NaN值(iphone sdk)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能重复:

目标C - 浮动检查纳米

确定NSNumber是否为NaN

我对NaN值有疑问在CGFloat中,我如何检查数字是否有效?

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 ...

推荐答案

有一个在math.h中定义检查数字是否为nan inf等(我认为你可以在没有导入的情况下使用它)。

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)

还有一些其他有用的定义,如isinf, isnormal isfinite ,...

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

这篇关于如何检查Objective-C中的NaN值(iphone sdk)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆