Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Reapply hex fix
  • Loading branch information
huoyaoyuan committed Nov 28, 2023
commit df3740094868b708db8c0478c6ec4d68ddaa8501
Original file line number Diff line number Diff line change
Expand Up @@ -480,6 +480,11 @@ internal static ParsingStatus TryParseBigIntegerHexNumberStyle(ReadOnlySpan<char

Debug.Assert(partialDigitCount == 0 && bitsBufferPos == -1);

if (isNegative)
{
NumericsHelpers.DangerousMakeTwosComplement(bitsBuffer);
}

// BigInteger requires leading zero blocks to be truncated.
bitsBuffer = bitsBuffer.TrimEnd(0u);

Expand All @@ -491,26 +496,15 @@ internal static ParsingStatus TryParseBigIntegerHexNumberStyle(ReadOnlySpan<char
sign = 0;
bits = null;
}
else if (bitsBuffer.Length == 1)
else if (bitsBuffer.Length == 1 && bitsBuffer[0] <= int.MaxValue)
{
sign = (int)bitsBuffer[0];
sign = (int)bitsBuffer[0] * (isNegative ? -1 : 1);
bits = null;

if ((!isNegative && sign < 0) || sign == int.MinValue)
{
bits = new[] { (uint)sign };
sign = isNegative ? -1 : 1;
}
}
else
{
sign = isNegative ? -1 : 1;
bits = bitsBuffer.ToArray();

if (isNegative)
{
NumericsHelpers.DangerousMakeTwosComplement(bits);
}
}

result = new BigInteger(sign, bits);
Expand Down