```(0.0).equals(-0.0) // false (0.0) == (-0.0) ...
# announcements
y
Copy code
(0.0).equals(-0.0)  // false
(0.0) == (-0.0)     // true
Does anyone can explain it?
p
Similar case was discussed yesterday. Seems like runtime vs compile time calculation. Report a bug.
👍 1
it's not a bug
c
"-0.0 is considered less than 0.0" from ghedeon's link
p
@ghedeon thanks for the link!
i
Yeah, @ghedeon is right, it behaves as specified. The bug that was discussed earlier is about double comparisons in constant expressions: https://youtrack.jetbrains.com/issue/KT-30282
y
@commanderpepper if so, why does
(0.0) == (-0.0)
return
true
?
i
The operator
==
uses IEEE-754 order, which considers them equal. The function
equals
uses total order, so these values are distinct.
s
So, does
==
not actually always translate to a
.equals()
call?
i
🍾 1
g
Right, not for these types. In this case
equals
behaves differently
to support generic use cases and provide total ordering
. So, it's good for sorting and stuff.