Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Commit

Permalink
Fixing TryNumberToDecimal to check the last digit in the buffer, if i…
Browse files Browse the repository at this point in the history
…t exists
  • Loading branch information
tannergooding committed Nov 1, 2018
1 parent 627d5a1 commit fb7fe2a
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/System.Private.CoreLib/shared/System/Number.Parsing.cs
Expand Up @@ -1592,11 +1592,20 @@ private static unsafe bool TryNumberToDecimal(ref NumberBuffer number, ref decim

if (c >= '5')
{
if ((c == '5') && ((low64 & 1) == 0) && !number.HasNonZeroTail)
if ((c == '5') && ((low64 & 1) == 0))
{
// When the next digit is 5, the number is even, and all following digits are zero
// we don't need to round.
goto NoRounding;
c = *++p;

// At this point we should either be at the end of the buffer, or just
// have a single rounding digit left, and the next should be the end
Debug.Assert((c == 0) || (*++p == 0));

if (((c == 0) || c == '0') && !number.HasNonZeroTail)
{
// When the next digit is 5, the number is even, and all following digits are zero
// we don't need to round.
goto NoRounding;
}
}

if (++low64 == 0 && ++high == 0)
Expand Down

0 comments on commit fb7fe2a

Please sign in to comment.