init(nan:signaling:)
Creates a NaN (“not a number”) value with the specified payload.
Declaration
init(nan payload: Float.RawSignificand, signaling: Bool)Parameters
- payload:
The payload to use for the new NaN value.
- signaling:
Pass
trueto create a signaling NaN orfalseto 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 isNaN property.
let x = Float(nan: 0, signaling: false)
print(x == .nan)
// Prints "false"
print(x.isNaN)
// Prints "true"