From cd20bb944fec9402764f58a5737cad12046a3457 Mon Sep 17 00:00:00 2001 From: Denis Paranichev <48580269+denis-paranichev@users.noreply.github.com> Date: Thu, 1 Feb 2024 20:13:33 +0300 Subject: [PATCH] [RISC-V] Test TotalOrderIeee754ComparerTests: Fix NFloat - NaN testcases for RISC-V (#97340) * Fix ieeeComparerTests NFloat NaN testcases for RISC-V * Fix comment * Specify test data for NaN test cases based on platform bitness * Delete extra comment * Fix CI failure --------- Co-authored-by: d.paranichev --- .../Numerics/TotalOrderIeee754ComparerTests.cs | 36 ++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Runtime/tests/System/Numerics/TotalOrderIeee754ComparerTests.cs b/src/libraries/System.Runtime/tests/System/Numerics/TotalOrderIeee754ComparerTests.cs index 019aabc..9ec0d21 100644 --- a/src/libraries/System.Runtime/tests/System/Numerics/TotalOrderIeee754ComparerTests.cs +++ b/src/libraries/System.Runtime/tests/System/Numerics/TotalOrderIeee754ComparerTests.cs @@ -94,9 +94,41 @@ namespace System.Runtime.Tests Assert.Equal(result, Math.Sign(comparer.Compare(x, y))); } + public static IEnumerable NFloatTestData + { + get + { + 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[] { (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[] { (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 }; + } + } + } + [Theory] - [MemberData(nameof(SingleTestData))] - public void TotalOrderTestNFloat(float x, float y, int result) + [MemberData(nameof(NFloatTestData))] + public void TotalOrderTestNFloat(NFloat x, NFloat y, int result) { var comparer = new TotalOrderIeee754Comparer(); Assert.Equal(result, Math.Sign(comparer.Compare(x, y))); -- 2.7.4