Creates a NaN (“not a number”) value with the specified payload.
SDK
- Xcode 8.0+
Framework
- Swift Standard Library
Declaration
init(nan payload: Double.RawSignificand , signaling: Bool)
Parameters
payload
The payload to use for the new NaN value.
signaling
Pass
true
to create a signaling NaN orfalse
to create a quiet NaN.
Discussion
NaN values compare not equal to every value, including themselves. Most operations with a NaN operand produce a NaN result. Don’t use the equal-to operator (==
) to test whether a value is NaN. Instead, use the value’s is
property.
let x = Double(nan: 0, signaling: false)
print(x == .nan)
// Prints "false"
print(x.isNaN)
// Prints "true"