From a44b103da92e767d235ac3d95ee4fc76e2e9a9af Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Thu, 27 Jan 2022 17:41:50 +0100 Subject: [PATCH] [WASM] Fix invalid equals/hashCode for Double.NaN and Float.NaN --- .../stdlib/wasm/builtins/kotlin/Primitives.kt | 27 +++++++------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt index 06ba2f918ca..d03ec2fe507 100644 --- a/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt +++ b/libraries/stdlib/wasm/builtins/kotlin/Primitives.kt @@ -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() }