Skip to content

Commit 36e0432

Browse files
authored
Big-endian fix for DoubleTests.cs:ParsePatterns (#54818)
The recently added DoubleTests.cs:ParsePatterns test case incorrectly swaps characters of the hexadecimal representation of the floating-point numbers under test on big-endian platforms.
1 parent b056b7b commit 36e0432

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libraries/System.Runtime/tests/System/DoubleTests.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Globalization;
66
using System.IO;
7+
using System.Linq;
78
using Xunit;
89

910
#pragma warning disable xUnit1025 // reporting duplicate test cases due to not distinguishing 0.0 from -0.0, NaN from -NaN
@@ -349,15 +350,12 @@ public static void Parse(string value, NumberStyles style, IFormatProvider provi
349350

350351
internal static string SplitPairs(string input)
351352
{
352-
string[] splitPairs = input.Split('-');
353-
string ret = "";
354-
foreach (var pair in splitPairs)
353+
if (!BitConverter.IsLittleEndian)
355354
{
356-
string reversedPair = Reverse(pair);
357-
ret += reversedPair;
355+
return input.Replace("-", "");
358356
}
359357

360-
return ret;
358+
return string.Concat(input.Split('-').Select(pair => Reverse(pair)));
361359
}
362360

363361
internal static string Reverse(string s)

0 commit comments

Comments
 (0)