如何检查inf? Swift xcode7

时间:2016-11-01 15:34:59

标签: swift

如果计算结果不是无限的,我如何检查Swift?

下面我的代码在打印后崩溃了“dividepointsbyrest is inf“。”如果dividepointsbyrest!= nil“检查nil。'如果dividepointsbyrest!= inf'不起作用。

var dividepointsbyrest = (BPMpoints / restDouble)
    print("dividepointsbyrest is") 
    print(dividepointsbyrest) 

    var BPMpercentD = 100.0 * dividepointsbyrest

1 个答案:

答案 0 :(得分:19)

Double具有isInfinite / isFinite属性。

if dividepointsbyrest.isInfinite {
    print("dividepointsbyrest is infinite")
}

if dividepointsbyrest.isFinite {
    print("dividepointsbyrest is finite")
}