It looks like this is true in other languages as well (see thread on C++), but does anyone know why you can't check the result of a negative square root against the Double.NaN
or Double.quietNaN
properties in Swift's Double
struct?
Here is some code I ran in a Playground:
sqrt(-5.0) // (not a number)
Double.NaN // (not a number)
Double.quietNaN // (not a number)
Double.NaN == sqrt(-5.0) // false
Double.quietNaN == sqrt(-5.0) // false
It seems that the Swift playground is printing sqrt(-5.0)
, Double.NaN
, and Double.quietNaN
with the same error string, but that they have different programmatic representations. I can't figure out why this is happening. Any thoughts?