Skip to content

Commit

Permalink
Big-endian fix for DoubleTests.cs:ParsePatterns (dotnet#54818)
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
uweigand authored Jun 29, 2021
1 parent b056b7b commit 36e0432
Showing 1 changed file with 4 additions and 6 deletions.
10 changes: 4 additions & 6 deletions src/libraries/System.Runtime/tests/System/DoubleTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;
using Xunit;

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

internal static string SplitPairs(string input)
{
string[] splitPairs = input.Split('-');
string ret = "";
foreach (var pair in splitPairs)
if (!BitConverter.IsLittleEndian)
{
string reversedPair = Reverse(pair);
ret += reversedPair;
return input.Replace("-", "");
}

return ret;
return string.Concat(input.Split('-').Select(pair => Reverse(pair)));
}

internal static string Reverse(string s)
Expand Down

0 comments on commit 36e0432

Please sign in to comment.