simon.vergauwen
02/05/2021, 12:33 PM(Double.NaN == Double.NaN).let(::println) // false
(listOf(Double.NaN) == listOf(Double.NaN)).let(::println) // true
holgerbrandl
02/05/2021, 1:13 PM.let(::println)
is not an extension in the stdlib Any.println()
?simon.vergauwen
02/05/2021, 1:25 PMlet(::println)
or also(::println)
.
The question here is, is it expected that Double.NaN == Double.NaN
is false
but when the value is wrapped in listOf
it suddenly becomes true
. I was assuming that the equals
implemented by List
would delegating to Double#equals
.
And if that is the case, why does listOf(Double.NaN) == listOf(Double.NaN)
result in true
.holgerbrandl
02/05/2021, 1:28 PMilya.gorbunov
02/05/2021, 2:03 PM==
is not eqivalent to calling equals
when comparing doublesilya.gorbunov
02/05/2021, 2:06 PMsimon.vergauwen
02/05/2021, 2:14 PM==
is not the same as equals
😄 I thought ==
was a symbolic operator for equals
but I guess that's not the case.
Is this only different for floating-point numbers? Or are there other scenarios where ==
behaves differenrltly from equals
?holgerbrandl
02/05/2021, 2:29 PMa
and b
are statically known in the example so that referential equality should be used?simon.vergauwen
02/05/2021, 2:44 PMDouble.NaN === Double.NaN
also results in false
.turansky
02/05/2021, 2:46 PMedrd
02/06/2021, 12:21 PMHowever, to support generic use cases and provide total ordering, when the operands are not statically typed as floating point numbers (e.g.,Any
, a type parameter), the operations use theComparable<...>
andequals
implementations forcompareTo
andFloat
, which disagree with the standard, so that:Double
is considered equal to itselfNaN
is considered greater than any other element includingNaN
POSITIVE_INFINITY
Seems like sinceis considered less than-0.0
0.0
listOf(Double.NaN)
at runtime becomes List<Any>
because of generic type erasure, equality will follow the rules above.