private BigInteger AddToMagnitude(
int[] magToAdd)
{
int[] big, small;
if (this.magnitude.Length < magToAdd.Length)
{
big = magToAdd;
small = this.magnitude;
}
else
{
big = this.magnitude;
small = magToAdd;
}
// Conservatively avoid over-allocation when no overflow possible
uint limit = uint.MaxValue;
if (big.Length == small.Length)
limit -= (uint) small[0];
bool possibleOverflow = (uint) big[0] >= limit;
int[] bigCopy;
if (possibleOverflow)
{
bigCopy = new int[big.Length + 1];
big.CopyTo(bigCopy, 1);
}
else
{
bigCopy = (int[]) big.Clone();
}
bigCopy = AddMagnitudes(bigCopy, small);
return new BigInteger(this.sign, bigCopy, possibleOverflow);
}