Dimitri T Dimitri T - 11 months ago 90
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")

var BPMpercentD = 100.0 * dividepointsbyrest

Answer Source

Double has an isInfinite/isFinite properties for that.

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


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