[WASM] Fix invalid equals/hashCode for Double.NaN and Float.NaN

This commit is contained in:
Igor Yakovlev
2022-01-27 17:41:50 +01:00
parent ea76501f9e
commit a44b103da9
@@ -1543,8 +1543,8 @@ public class Float private constructor(public val value: Float) : Number(), Comp
if (this > other) return 1
if (this < other) return -1
val thisBits = this.bits()
val otherBits = other.bits()
val thisBits = this.toBits()
val otherBits = other.toBits()
// Canonical NaN bits representation higher than any other value
return thisBits.compareTo(otherBits)
@@ -1761,7 +1761,7 @@ public class Float private constructor(public val value: Float) : Number(), Comp
wasm_f64_promote_f32(this)
public inline fun equals(other: Float): Boolean =
bits() == other.bits()
toBits() == other.toBits()
public override fun equals(other: Any?): Boolean =
other is Float && this.equals(other)
@@ -1770,11 +1770,7 @@ public class Float private constructor(public val value: Float) : Number(), Comp
dtoa(this.toDouble())
public override inline fun hashCode(): Int =
bits()
@PublishedApi
@WasmOp(WasmOp.I32_REINTERPRET_F32)
internal fun bits(): Int = implementedAsIntrinsic
toBits()
}
/**
@@ -1870,8 +1866,8 @@ public class Double private constructor(public val value: Double) : Number(), Co
if (this > other) return 1
if (this < other) return -1
val thisBits = this.bits()
val otherBits = other.bits()
val thisBits = this.toBits()
val otherBits = other.toBits()
// Canonical NaN bits representation higher than any other value
return thisBits.compareTo(otherBits)
@@ -2084,18 +2080,13 @@ public class Double private constructor(public val value: Double) : Number(), Co
this
public inline fun equals(other: Double): Boolean =
this.bits() == other.bits()
this.toBits() == other.toBits()
public override fun equals(other: Any?): Boolean =
other is Double && this.bits() == other.bits()
other is Double && this.toBits() == other.toBits()
public override fun toString(): String =
dtoa(this)
public override inline fun hashCode(): Int = bits().hashCode()
@PublishedApi
@WasmOp(WasmOp.I64_REINTERPRET_F64)
internal fun bits(): Long =
implementedAsIntrinsic
public override inline fun hashCode(): Int = toBits().hashCode()
}