Skip to content

Commit 5f08f95

Browse files
tannergoodingdotnet-bot
authored andcommitted
Fixing up the Double/Single parsing code to be correct (dotnet#20707)
* Don't normalize -0.0 to 0.0 when parsing * Updating NumberBuffer to validate the constructor inputs * Updating NumberToDouble to just get the precision * Don't check for non-significant zero's in NumberToDouble * Updating Number.BigInteger to carry additional space for the worst-case scenario * Removing some dead code from double.TryParse * Updating NumberToDouble to use the RealParser implementation from Roslyn * Fixing TryNumberToDouble and TryNumberToSingle to apply the appropriate sign. * Adding a fast path for double/single parsing when we have <= 15 digits and an absolute scale <= 22 * Update NumberBuffer to also track whether any input digits past maxDigCount were non-zero * Renaming NumberToFloatingPointBitsRoslyn to NumberToFloatingPointBits * Updating TryNumberToDouble and TryNumberToSingle to support Overflow to Infinity * Fixing a Debug.Assert in TryParseNumber * Fixing `DecimalNumberBufferLength` to 30 * Renaming NumberToFloatingPointBitsRoslyn to NumberToFloatingPointBits * Clarifying the NumberBufferLength comments * Fixing TryNumberToDecimal to check the last digit in the buffer, if it exists * Disable some CoreFX tests due to the single/double/decimal parsing fixes * Fix TryNumberToDecimal to not modify the value of p in the assert. Co-Authored-By: tannergooding <[email protected]> * Updating NumberToFloatingPointBits to use single-precision arithmetic and extended-precision multiplication where possible * Splitting the NumberToFloatingPointBits code into a fast and slow-path method * Ensure Roslyn is properly attributed. * Removing the 80-bit extended precision fast path for NumberToFloatingPointBits, due to a bug * Fixing the double and single parser to ignore case for Infinity and NaN * Add a clarifying comment to Number.NumberToFloatingPointBits that the code has been modified from the original source. * Removing the remaining code that was used by the 80-bit extended precision fast-path in NumberToFloatingPointBits * Adding a missing comma to the CoreFX.issues.json * Remove licensing "glue" and re-release the Roslyn RealParser code under the MIT license. * Some minor cleanup to the NumberToFloatingPointBits code. Signed-off-by: dotnet-bot <[email protected]>
1 parent 889f017 commit 5f08f95

10 files changed

+1320
-568
lines changed

src/Common/src/CoreLib/System.Private.CoreLib.Shared.projitems

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,7 @@
294294
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Formatting.cs" />
295295
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Grisu3.cs" />
296296
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberBuffer.cs" />
297-
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberToDouble.cs" />
297+
<Compile Include="$(MSBuildThisFileDirectory)System\Number.NumberToFloatingPointBits.cs" />
298298
<Compile Include="$(MSBuildThisFileDirectory)System\Number.Parsing.cs" />
299299
<Compile Include="$(MSBuildThisFileDirectory)System\NullReferenceException.cs" />
300300
<Compile Include="$(MSBuildThisFileDirectory)System\ObjectDisposedException.cs" />

src/Common/src/CoreLib/System/Double.cs

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -341,28 +341,7 @@ public static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, IFormatPro
341341

342342
private static bool TryParse(ReadOnlySpan<char> s, NumberStyles style, NumberFormatInfo info, out double result)
343343
{
344-
bool success = Number.TryParseDouble(s, style, info, out result, out _);
345-
if (!success)
346-
{
347-
ReadOnlySpan<char> sTrim = s.Trim();
348-
if (sTrim.EqualsOrdinal(info.PositiveInfinitySymbol))
349-
{
350-
result = PositiveInfinity;
351-
}
352-
else if (sTrim.EqualsOrdinal(info.NegativeInfinitySymbol))
353-
{
354-
result = NegativeInfinity;
355-
}
356-
else if (sTrim.EqualsOrdinal(info.NaNSymbol))
357-
{
358-
result = NaN;
359-
}
360-
else
361-
{
362-
return false; // We really failed
363-
}
364-
}
365-
return true;
344+
return Number.TryParseDouble(s, style, info, out result);
366345
}
367346

368347
//

0 commit comments

Comments
 (0)