Address bugs in BigInteger (dotnet/coreclr#27280)
authorts2do <tsdodo@gmail.com>
Mon, 11 Nov 2019 23:35:28 +0000 (17:35 -0600)
committerAnton Lapounov <antonl@microsoft.com>
Mon, 11 Nov 2019 23:35:28 +0000 (15:35 -0800)
commitbf7cd55eeb389b2458cef4ed332a5cdab5e9d315
treec2d0c99a86d93e17da603fde85206898a25e2903
parentbac5d5e6340b86a5f96fd42fed0b3d8bbc28c28e
Address bugs in BigInteger (dotnet/coreclr#27280)

* Method Add(ref BigInteger lhs, uint value, ref BigInteger result) would store most of the result blocks into lhs instead of result.
* Method ShiftLeft(ulong input, uint shift, ref BigInteger output) with a shift argument exceeding 32 would generally compute the higher blocks incorrectly.
* Multiply(ref BigInteger lhs, uint value, ref BigInteger result) would not set result._length in some cases.
* IsZero() would incorrectly return false for non-canonical zeros with _length > 0.

Fix:
* Inline Add(ref BigInteger, uint, ref BigInteger) into Add(uint).
* Inline ShiftLeft(ulong, uint, ref BigInteger) into Pow2.
* Inline ExtendBlock and ExtendBlocks into Pow2.
* Properly handle 0 in SetUInt32 and SetUInt64.

Commit migrated from https://github.com/dotnet/coreclr/commit/65a7947491685a6a3479525334e4178f8eab4b75
src/libraries/System.Private.CoreLib/src/System/Number.BigInteger.cs
src/libraries/System.Private.CoreLib/src/System/Number.Dragon4.cs