如何在Objective-C(iOS)中检查NaN值 [英] How to check for NaN value in Objective-C (iOS)

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

问题描述

可能的重复项:
Objective-C-浮动检查nan
确定NSNumber是否为NaN

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

我在CGFloat中的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.

推荐答案

有一个定义,用于检查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 是有限的,...

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

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

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