What's up with this behavior: ```fun main() { ...
# stdlib
n
What's up with this behavior:
Copy code
fun main() {
    val x = Double.NaN
    println(x == x)
    println(listOf(x) == listOf(x))
}
e
NaN != NaN under floating point comparison, as per IEEE 754. NaN == NaN under object comparison, otherwise hashCode is broken see https://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#equals-java.lang.Object-
n
Wouldn't almost everyone regard hash tables with floating point keys as being a broke thing to do to start with?
e
in some languages yes, but the behavior is well-defined in Java (and Kotlin)
n
I don't think it's generally regarded as broken "in some languages", but just generally a fundamentally broken thing to do, given how weak the guarantees around floating point arithmetic actually are
at any rate seems like a poor trade-off to me but thanks for explaining the reason