Dimitri T Dimitri T - 1 month ago 19
Swift Question

How to check for inf? Swift xcode7

How do I check in Swift if the result of a calculation is not infinite?

My code below is crashing after printing that"dividepointsbyrest is
inf". "if dividepointsbyrest != nil" checks for nil. 'if dividepointsbyrest != inf' does not work.

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

var BPMpercentD = 100.0 * dividepointsbyrest

Answer

Double has an isInfinite/isFinite properties for that.

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

or

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