Comparing NaN in Kotlin
<p>So I recently started loving the language kotlin. Today, while comparing doubles, I came across the inevitable <code>NaN</code>.</p>

<pre><code>fun main(args: Array&lt;String&gt;) {
    val nan = Double.NaN
    println("1: " + (nan == nan))
    println("2: " + (nan == (nan as Number)))
    println("3: " + ((nan as Number) == nan))
}
</code></pre>

<p><em>N.B: (</em><code>Double</code> <em>is a subtype of</em> <a href="https://kotlinlang.org/api/latest/jvm/stdlib/kotlin/-number/" rel="noreferrer"><code>Number</code></a><em>)</em></p>

<p>Running the above code yields:</p>

<pre><code>1: false
2: true
3: true
</code></pre>

<p>I understand that <a href="https://stackoverflow.com/questions/8819738/why-does-double-nan-double-nan-return-false/8820592#8820592">comparing</a> with <code>NaN</code> in Java returns <code>false</code>, so I would expect <code>false</code> for all expressions.</p>

<p>How can this behavior be explained?
What is the rationale behind it?</p>