From 18cd0cd44e3596078559c7855b79c69d9f237c70 Mon Sep 17 00:00:00 2001 From: "d.paranichev" Date: Mon, 22 Jan 2024 22:58:57 +0300 Subject: [PATCH 1/5] Fix ieeeComparerTests NFloat NaN testcases for RISC-V --- .../TotalOrderIeee754ComparerTests.cs | 32 ++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs index 019aabc2f227e..8c40acdaa3620 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs @@ -94,8 +94,38 @@ public void TotalOrderTestHalf(Half x, Half y, int result) Assert.Equal(result, Math.Sign(comparer.Compare(x, y))); } + public static IEnumerable NFloatTestData + { + get + { + yield return new object[] { 0.0f, 0.0f, 0 }; + yield return new object[] { -0.0f, -0.0f, 0 }; + yield return new object[] { 0.0f, -0.0f, 1 }; + yield return new object[] { -0.0f, 0.0f, -1 }; + yield return new object[] { 0.0f, 1.0f, -1 }; + yield return new object[] { float.PositiveInfinity, 1.0f, 1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), 1.0f, 1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), float.PositiveInfinity, 1 }; + yield return new object[] { float.NaN, float.NaN, 0 }; + if (PlatformDetection.IsRiscV64Process) // float->double cast does not preserve payload and sign on RISC-V + { + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, 1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, 1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), 0 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), 0 }; // implementation defined, not part of IEEE 754 totalOrder + } + else + { + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, -1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, -1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), -1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), -1 }; // implementation defined, not part of IEEE 754 totalOrder + } + } + } + [Theory] - [MemberData(nameof(SingleTestData))] + [MemberData(nameof(NFloatTestData))] public void TotalOrderTestNFloat(float x, float y, int result) { var comparer = new TotalOrderIeee754Comparer(); From 0992c575bf8e50ffc02f0f8997811bf7e1962f1f Mon Sep 17 00:00:00 2001 From: "d.paranichev" Date: Mon, 22 Jan 2024 23:16:41 +0300 Subject: [PATCH 2/5] Fix comment --- .../System/Numerics/TotalOrderIeee754ComparerTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs index 8c40acdaa3620..ffd0f04005ad1 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs @@ -107,7 +107,7 @@ public static IEnumerable NFloatTestData yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), 1.0f, 1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), float.PositiveInfinity, 1 }; yield return new object[] { float.NaN, float.NaN, 0 }; - if (PlatformDetection.IsRiscV64Process) // float->double cast does not preserve payload and sign on RISC-V + if (PlatformDetection.IsRiscV64Process) // float->double cast does not preserve NaN payload and sign on RISC-V { yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, 1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, 1 }; From ee575aee73689b2289b50d76bc4700a0568546d8 Mon Sep 17 00:00:00 2001 From: "d.paranichev" Date: Mon, 29 Jan 2024 13:00:09 +0300 Subject: [PATCH 3/5] Specify test data for NaN test cases based on platform bitness --- .../TotalOrderIeee754ComparerTests.cs | 26 ++++++++++--------- 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs index ffd0f04005ad1..52707144c5a57 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs @@ -103,30 +103,32 @@ public static IEnumerable NFloatTestData yield return new object[] { 0.0f, -0.0f, 1 }; yield return new object[] { -0.0f, 0.0f, -1 }; yield return new object[] { 0.0f, 1.0f, -1 }; - yield return new object[] { float.PositiveInfinity, 1.0f, 1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), 1.0f, 1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), float.PositiveInfinity, 1 }; - yield return new object[] { float.NaN, float.NaN, 0 }; - if (PlatformDetection.IsRiscV64Process) // float->double cast does not preserve NaN payload and sign on RISC-V + yield return new object[] { NFloat.PositiveInfinity, 1.0f, 1 }; + yield return new object[] { NFloat.NaN, NFloat.NaN, 0 }; + if (Environment.Is64BitProcess) { - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, 1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, 1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), 0 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), 0 }; // implementation defined, not part of IEEE 754 totalOrder + yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), 1.0d, 1 }; + yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), NFloat.PositiveInfinity, 1 }; + yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), NFloat.NegativeInfinity, -1 }; + yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), -1.0d, -1 }; + yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), -1 }; + yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000001), -1 }; // implementation defined, not part of IEEE 754 totalOrder } else { - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), float.NegativeInfinity, -1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), 1.0f, 1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), NFloat.PositiveInfinity, 1 }; + yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), NFloat.NegativeInfinity, -1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, -1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), -1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), -1 }; // implementation defined, not part of IEEE 754 totalOrder } - } + } } [Theory] [MemberData(nameof(NFloatTestData))] - public void TotalOrderTestNFloat(float x, float y, int result) + public void TotalOrderTestNFloat(NFloat x, NFloat y, int result) { var comparer = new TotalOrderIeee754Comparer(); Assert.Equal(result, Math.Sign(comparer.Compare(x, y))); From fec33c4b4ddcf71b055807e01677060480655e83 Mon Sep 17 00:00:00 2001 From: "d.paranichev" Date: Tue, 30 Jan 2024 12:54:11 +0300 Subject: [PATCH 4/5] Delete extra comment --- .../System/Numerics/TotalOrderIeee754ComparerTests.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs index 52707144c5a57..2a3e710de1076 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs @@ -112,7 +112,7 @@ public static IEnumerable NFloatTestData yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), NFloat.NegativeInfinity, -1 }; yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), -1.0d, -1 }; yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), -1 }; - yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000001), -1 }; // implementation defined, not part of IEEE 754 totalOrder + yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000001), -1 }; } else { @@ -121,7 +121,7 @@ public static IEnumerable NFloatTestData yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), NFloat.NegativeInfinity, -1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, -1 }; yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), -1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), -1 }; // implementation defined, not part of IEEE 754 totalOrder + yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), -1 }; } } } From 1f804dbb2ad3c7ee5f98bc79e48a1571dc477e7a Mon Sep 17 00:00:00 2001 From: "d.paranichev" Date: Wed, 31 Jan 2024 19:29:55 +0300 Subject: [PATCH 5/5] Fix CI failure --- .../TotalOrderIeee754ComparerTests.cs | 36 +++++++++---------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs index 2a3e710de1076..9ec0d213a9113 100644 --- a/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs +++ b/src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs @@ -98,30 +98,30 @@ public static IEnumerable NFloatTestData { get { - yield return new object[] { 0.0f, 0.0f, 0 }; - yield return new object[] { -0.0f, -0.0f, 0 }; - yield return new object[] { 0.0f, -0.0f, 1 }; - yield return new object[] { -0.0f, 0.0f, -1 }; - yield return new object[] { 0.0f, 1.0f, -1 }; - yield return new object[] { NFloat.PositiveInfinity, 1.0f, 1 }; + yield return new object[] { (NFloat)(0.0f), (NFloat)(0.0f), 0 }; + yield return new object[] { (NFloat)(-0.0f), (NFloat)(-0.0f), 0 }; + yield return new object[] { (NFloat)(0.0f), (NFloat)(-0.0f), 1 }; + yield return new object[] { (NFloat)(-0.0f), (NFloat)(0.0f), -1 }; + yield return new object[] { (NFloat)(0.0f), (NFloat)(1.0f), -1 }; + yield return new object[] { NFloat.PositiveInfinity, (NFloat)(1.0f), 1 }; yield return new object[] { NFloat.NaN, NFloat.NaN, 0 }; if (Environment.Is64BitProcess) { - yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), 1.0d, 1 }; - yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), NFloat.PositiveInfinity, 1 }; - yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), NFloat.NegativeInfinity, -1 }; - yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), -1.0d, -1 }; - yield return new object[] { BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), -1 }; - yield return new object[] { BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), BitConverter.UInt64BitsToDouble(0x7FF80000_00000001), -1 }; + yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), (NFloat)(1.0d), 1 }; + yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), NFloat.PositiveInfinity, 1 }; + yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), NFloat.NegativeInfinity, -1 }; + yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), (NFloat)(-1.0d), -1 }; + yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), (NFloat)(BitConverter.UInt64BitsToDouble(0x7FF80000_00000000)), -1 }; + yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), (NFloat)(BitConverter.UInt64BitsToDouble(0x7FF80000_00000001)), -1 }; } else { - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), 1.0f, 1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), NFloat.PositiveInfinity, 1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), NFloat.NegativeInfinity, -1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), -1.0f, -1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0xFFC00000), BitConverter.UInt32BitsToSingle(0x7FC00000), -1 }; - yield return new object[] { BitConverter.UInt32BitsToSingle(0x7FC00000), BitConverter.UInt32BitsToSingle(0x7FC00001), -1 }; + yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), (NFloat)(1.0f), 1 }; + yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), NFloat.PositiveInfinity, 1 }; + yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), NFloat.NegativeInfinity, -1 }; + yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), (NFloat)(-1.0f), -1 }; + yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), (NFloat)(BitConverter.UInt32BitsToSingle(0x7FC00000)), -1 }; + yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), (NFloat)(BitConverter.UInt32BitsToSingle(0x7FC00001)), -1 }; } } }