Skip to content
Permalink
Browse files

Fixing TryNumberToDecimal to check the last digit in the buffer, if i…

…t exists
  • Loading branch information...
tannergooding committed Nov 1, 2018
1 parent 627d5a1 commit fb7fe2a98ce5158bc5da4ac6a455be4d413fc2fe
Showing with 13 additions and 4 deletions.
  1. +13 −4 src/System.Private.CoreLib/shared/System/Number.Parsing.cs
@@ -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)

0 comments on commit fb7fe2a

Please sign in to comment.
You can’t perform that action at this time.