Skip to main content
Journey Uncommon Logo
JourneyUncommon
hardSwiftunsafeBitCast and pointersSingle-choice MCQ

Both lines below reinterpret the same 64-bit pattern as a `Double`. Given `i = -1` as Int64 (all bits set, which is an IEEE-754 NaN when read as a double), what does `print(d1 == d2)` output and why?

let i: Int64 = -1 let d1 = unsafeBitCast(i, to: Double.self) let d2 = Double(bitPattern: UInt64(bitPattern: i)) print(d1 == d2)