Skip to content

Commit 541857c

Browse files
denis-paranichevd.paranichev
andauthored
[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 <d.paranichev@partner.samsung.com>
1 parent 52e1ad3 commit 541857c

File tree

1 file changed

+34
-2
lines changed

1 file changed

+34
-2
lines changed

src/libraries/System.Runtime/tests/System.Runtime.Tests/System/Numerics/TotalOrderIeee754ComparerTests.cs

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,9 +94,41 @@ public void TotalOrderTestHalf(Half x, Half y, int result)
9494
Assert.Equal(result, Math.Sign(comparer.Compare(x, y)));
9595
}
9696

97+
public static IEnumerable<object[]> NFloatTestData
98+
{
99+
get
100+
{
101+
yield return new object[] { (NFloat)(0.0f), (NFloat)(0.0f), 0 };
102+
yield return new object[] { (NFloat)(-0.0f), (NFloat)(-0.0f), 0 };
103+
yield return new object[] { (NFloat)(0.0f), (NFloat)(-0.0f), 1 };
104+
yield return new object[] { (NFloat)(-0.0f), (NFloat)(0.0f), -1 };
105+
yield return new object[] { (NFloat)(0.0f), (NFloat)(1.0f), -1 };
106+
yield return new object[] { NFloat.PositiveInfinity, (NFloat)(1.0f), 1 };
107+
yield return new object[] { NFloat.NaN, NFloat.NaN, 0 };
108+
if (Environment.Is64BitProcess)
109+
{
110+
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), (NFloat)(1.0d), 1 };
111+
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), NFloat.PositiveInfinity, 1 };
112+
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), NFloat.NegativeInfinity, -1 };
113+
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), (NFloat)(-1.0d), -1 };
114+
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0xFFF80000_00000000), (NFloat)(BitConverter.UInt64BitsToDouble(0x7FF80000_00000000)), -1 };
115+
yield return new object[] { (NFloat)BitConverter.UInt64BitsToDouble(0x7FF80000_00000000), (NFloat)(BitConverter.UInt64BitsToDouble(0x7FF80000_00000001)), -1 };
116+
}
117+
else
118+
{
119+
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), (NFloat)(1.0f), 1 };
120+
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), NFloat.PositiveInfinity, 1 };
121+
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), NFloat.NegativeInfinity, -1 };
122+
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), (NFloat)(-1.0f), -1 };
123+
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0xFFC00000), (NFloat)(BitConverter.UInt32BitsToSingle(0x7FC00000)), -1 };
124+
yield return new object[] { (NFloat)BitConverter.UInt32BitsToSingle(0x7FC00000), (NFloat)(BitConverter.UInt32BitsToSingle(0x7FC00001)), -1 };
125+
}
126+
}
127+
}
128+
97129
[Theory]
98-
[MemberData(nameof(SingleTestData))]
99-
public void TotalOrderTestNFloat(float x, float y, int result)
130+
[MemberData(nameof(NFloatTestData))]
131+
public void TotalOrderTestNFloat(NFloat x, NFloat y, int result)
100132
{
101133
var comparer = new TotalOrderIeee754Comparer<NFloat>();
102134
Assert.Equal(result, Math.Sign(comparer.Compare(x, y)));

0 commit comments

Comments
 (0)