From 1052ebb44dfb518b2d4d549fef399e85cc3b7342 Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Tue, 25 Jan 2022 13:02:48 +0100 Subject: [PATCH] [WASM] Fix invalid rounding for Double to Int/Long conversion --- libraries/stdlib/wasm/src/kotlin/math/math.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/stdlib/wasm/src/kotlin/math/math.kt b/libraries/stdlib/wasm/src/kotlin/math/math.kt index 98335ede653..9de2fc101a7 100644 --- a/libraries/stdlib/wasm/src/kotlin/math/math.kt +++ b/libraries/stdlib/wasm/src/kotlin/math/math.kt @@ -474,7 +474,7 @@ public actual fun Double.roundToInt(): Int = when { isNaN() -> throw IllegalArgumentException("Cannot round NaN value.") this > Int.MAX_VALUE -> Int.MAX_VALUE this < Int.MIN_VALUE -> Int.MIN_VALUE - else -> kotlin.math.fdlibm.rint(this).toInt() + else -> floor(this + 0.5).toInt() } /** @@ -492,7 +492,7 @@ public actual fun Double.roundToLong(): Long = when { isNaN() -> throw IllegalArgumentException("Cannot round NaN value.") this > Long.MAX_VALUE -> Long.MAX_VALUE this < Long.MIN_VALUE -> Long.MIN_VALUE - else -> kotlin.math.fdlibm.rint(this).toLong() + else -> floor(this + 0.5).toLong() } // endregion