[Wasm/std] Fix invalid sign for FP rem operator

Fixed #KT-64829
This commit is contained in:
Igor Yakovlev
2024-01-22 18:56:02 +01:00
committed by Space Team
parent a15e88ba1e
commit 3e9b2573c5
3 changed files with 9 additions and 3 deletions
@@ -34,6 +34,7 @@ class FloorDivModTest {
check(10, 3, 3, 1)
check(-10, 3, -4, 2)
check(-10, -3, 3, -1)
check(-2, 2, -1, -0)
val values = listOf(1, -1, 2, -2, 3, -3, Int.MIN_VALUE, Int.MAX_VALUE)
for (a in values + 0) {
for (b in values) {
@@ -69,6 +70,7 @@ class FloorDivModTest {
check(10, 3, 3, 1)
check(-10, 3, -4, 2)
check(-10, -3, 3, -1)
check(-2, 2, -1, -0)
val values = listOf(1, -1, 2, -2, 3, -3, Long.MIN_VALUE, Long.MAX_VALUE)
for (a in values + 0) {
for (b in values) {
@@ -104,6 +106,7 @@ class FloorDivModTest {
check(10, 3, 3, 1)
check(-10, 3, -4, 2)
check(-10, -3, 3, -1)
check(-2, 2, -1, -0)
val values = listOf(1, -1, 2, -2, 3, -3, Byte.MIN_VALUE, Byte.MAX_VALUE)
for (a in values + 0) {
for (b in values) {
@@ -139,6 +142,7 @@ class FloorDivModTest {
check(10, 3, 3, 1)
check(-10, 3, -4, 2)
check(-10, -3, 3, -1)
check(-2, 2, -1, -0)
val values = listOf(1, -1, 2, -2, 3, -3, Short.MIN_VALUE, Short.MAX_VALUE)
for (a in values + 0) {
for (b in values) {
@@ -221,6 +225,7 @@ class FloorDivModTest {
check(10.125, 0.5, 0.125)
check(-10.125, 0.5, 0.375)
check(-10.125, -0.5, -0.125)
check(-2.0, 2.0, -0.0)
val large = 2.0.pow(53)
check(0.025, large, 0.025)
check(-0.025, large, expectedMod = large)
@@ -259,6 +264,7 @@ class FloorDivModTest {
check(10.125f, 0.5f, 0.125f)
check(-10.125f, 0.5f, 0.375f)
check(-10.125f, -0.5f, -0.125f)
check(-2.0f, 2.0f, -0.0f)
val large = 2.0f.pow(53)
check(0.025f, large, 0.025f)
check(-0.025f, large, expectedMod = large)
@@ -2155,7 +2155,7 @@ public class Float private constructor(private val value: Float) : Number(), Com
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public operator fun rem(other: Float): Float =
this - (wasm_f32_truncate(this / other) * other)
wasm_f32_copysign(this - (wasm_f32_truncate(this / other) * other), this)
/**
* Calculates the remainder of truncating division of this value (dividend) by the other value (divisor).
@@ -2565,7 +2565,7 @@ public class Double private constructor(private val value: Double) : Number(), C
@SinceKotlin("1.1")
@kotlin.internal.IntrinsicConstEvaluation
public operator fun rem(other: Double): Double =
this - (wasm_f64_truncate(this / other) * other)
wasm_f64_copysign(this - (wasm_f64_truncate(this / other) * other), this)
/**
* Returns this value incremented by one.