What is Double.isNaN in Swift?
Overview
Double.isNaN property in Swift is used to check if an instance of type double is NaN (Not a Number).
Syntax
Double.isNaN
Parameter
This function does not take any parameters.
Return value
The value returned is a boolean value.
Code example
// create some valueslet d1 = 1.2let d2 = 0.0let d3 = Double.infinity * 0.0let d4 = Double.infinitylet d5 = Double.nan * 2// check if Not a Numberprint(d1.isNaN) // falseprint(d2.isNaN) // falseprint(d3.isNaN) // trueprint(d4.isNaN) // falseprint(d5.isNaN) // true
Explanation
- Lines 2-6: We create some double values.
- Lines 9-13: We check to see if the values we created are
NaNand print the results to the console.