Matej Kormuth
12/26/2018, 11:21 PMdata class B(val a: Float, val b: Float)
data class A(val a: Float, val b: Float) {
override fun equals(other: Any?): Boolean {
if(other is A) {
return a == other.a && b == other.b
}
return false
}
}
fun main(args: Array<String>) {
println(0.0f == -0.0f) // true
println(B(0.0f, 0.0f) == B(0.0f, -0.0f)) // false
println(B(2f, 4f) == B(2f, 4f)) // true
println(A(0.0f, 0.0f) == A(0.0f, -0.0f)) // true (workaround)
}
Matej Kormuth
12/26/2018, 11:27 PMequals()
for the data class is returning false for comparison that otherwise returns (and should return) true.Matej Kormuth
12/26/2018, 11:28 PMid 'kotlin-multiplatform' version '1.3.11'
olonho
12/27/2018, 5:23 AMequals
section in https://docs.oracle.com/javase/7/docs/api/java/lang/Float.htmlMatej Kormuth
12/27/2018, 12:07 PMa
, b
properties represented as boxed types and not primitives? Or the `equals`and hashCode
are implemented in a way that even non-boxed types are considered as "boxed" during to comparison?olonho
12/27/2018, 12:20 PMequals
, for example println(0.0f.equals(-0.0f))
prints false
uli
12/27/2018, 7:49 PMolonho
12/27/2018, 8:15 PMuli
12/27/2018, 8:40 PMuli
12/27/2018, 8:45 PMprintln(0.0f.equals(-0.0f))
prints false
olonho
12/27/2018, 9:16 PMequals
and ==
is not the same operation for floatsuli
12/27/2018, 9:20 PM