Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check for inf? Swift xcode7

Tags:

swift

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
like image 576
Dimitri T Avatar asked Nov 01 '16 15:11

Dimitri T


1 Answers

Double has an isInfinite/isFinite properties for that.

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

or

if dividepointsbyrest.isFinite {
    print("dividepointsbyrest is finite")
}
like image 58
Craig Siemens Avatar answered Nov 04 '22 12:11

Craig Siemens