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
Double
has an isInfinite
/isFinite
properties for that.
if dividepointsbyrest.isInfinite {
print("dividepointsbyrest is infinite")
}
or
if dividepointsbyrest.isFinite {
print("dividepointsbyrest is finite")
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With