如果计算结果不是无限的,我如何检查Swift?
下面我的代码在打印后崩溃了“dividepointsbyrest is inf“。”如果dividepointsbyrest!= nil“检查nil。'如果dividepointsbyrest!= inf'不起作用。
var dividepointsbyrest = (BPMpoints / restDouble)
print("dividepointsbyrest is")
print(dividepointsbyrest)
var BPMpercentD = 100.0 * dividepointsbyrest
答案 0 :(得分:19)
Double
具有isInfinite
/ isFinite
属性。
if dividepointsbyrest.isInfinite {
print("dividepointsbyrest is infinite")
}
或
if dividepointsbyrest.isFinite {
print("dividepointsbyrest is finite")
}