Double.infinity
in Swift returns a positive infinity value. When compared, it is greater than all finite values and equal to infinite values.
Double.infinity
This method returns an infinity value inf
.
// Get infinitylet infValue = Double.infinity// Print the infinity valueprint(infValue)// Compare with other valueslet comp1 = infValue > 1 ? "greater" : "lesser"let comp2 = infValue < 1 ? "lesser" : "greater"let comp3 = infValue == Double.infinity ? "equal" : "lesser"// Print the resultsprint(comp1)print(comp2)print(comp3)
Double.infinity
, and store it in the variable infValue
.infValue
with some other values and infinity itself.