Terraria v1.4.4.9
Terraria source code documentation
Loading...
Searching...
No Matches

◆ operator>>()

static BigInteger System.Numerics.BigInteger.operator>> ( BigInteger value,
int shift )
inlinestatic

Definition at line 1736 of file BigInteger.cs.

1737 {
1738 if (shift == 0)
1739 {
1740 return value;
1741 }
1742 if (shift == int.MinValue)
1743 {
1744 return value << int.MaxValue << 1;
1745 }
1746 if (shift < 0)
1747 {
1748 return value << -shift;
1749 }
1750 (int Quotient, int Remainder) tuple = Math.DivRem(shift, 32);
1751 int item = tuple.Quotient;
1752 int item2 = tuple.Remainder;
1753 Span<uint> span = stackalloc uint[1];
1754 Span<uint> span2 = span;
1755 Span<uint> xd = span2;
1756 bool partsForBitManipulation = GetPartsForBitManipulation(ref value, ref xd);
1757 bool flag = false;
1758 if (partsForBitManipulation)
1759 {
1760 if (shift >= 32 * xd.Length)
1761 {
1762 return MinusOne;
1763 }
1764 if (xd != span2)
1765 {
1766 if (xd.Length <= 64)
1767 {
1768 span = stackalloc uint[64];
1769 span2 = span.Slice(0, xd.Length);
1770 xd.CopyTo(span2);
1771 xd = span2;
1772 }
1773 else
1774 {
1775 xd = xd.ToArray();
1776 }
1777 }
1778 NumericsHelpers.DangerousMakeTwosComplement(xd);
1779 flag = item2 == 0 && xd[^1] == 0;
1780 }
1781 int num = xd.Length - item + (flag ? 1 : 0);
1782 uint[] valueArray = null;
1783 Span<uint> span3 = default(Span<uint>);
1784 if (num > 0)
1785 {
1786 Span<uint> span4;
1787 if (num <= 64)
1788 {
1789 span = stackalloc uint[64];
1790 span4 = span.Slice(0, num);
1791 }
1792 else
1793 {
1794 span4 = (valueArray = new uint[num]);
1795 }
1796 span3 = span4;
1797 }
1798 if (item2 == 0)
1799 {
1800 for (int num2 = xd.Length - 1; num2 >= item; num2--)
1801 {
1802 span3[num2 - item] = xd[num2];
1803 }
1804 }
1805 else
1806 {
1807 int num3 = 32 - item2;
1808 uint num4 = 0u;
1809 for (int num5 = xd.Length - 1; num5 >= item; num5--)
1810 {
1811 uint num6 = xd[num5];
1812 if (partsForBitManipulation && num5 == xd.Length - 1)
1813 {
1814 span3[num5 - item] = (num6 >> item2) | (uint)(-1 << num3);
1815 }
1816 else
1817 {
1818 span3[num5 - item] = (num6 >> item2) | num4;
1819 }
1820 num4 = num6 << num3;
1821 }
1822 }
1823 if (partsForBitManipulation)
1824 {
1825 if (flag)
1826 {
1827 span3[^1] = uint.MaxValue;
1828 }
1829 NumericsHelpers.DangerousMakeTwosComplement(span3);
1830 }
1831 return new BigInteger(span3, valueArray, partsForBitManipulation);
1832 }
static bool GetPartsForBitManipulation(ref BigInteger x, ref Span< uint > xd)
static BigInteger MinusOne
Definition BigInteger.cs:36
static BigInteger Remainder(BigInteger dividend, BigInteger divisor)

References System.Numerics.BigInteger.BigInteger(), System.Span< T >.CopyTo(), System.Numerics.NumericsHelpers.DangerousMakeTwosComplement(), System.Math.DivRem(), System.Numerics.BigInteger.GetPartsForBitManipulation(), System.item, System.Span< T >.Length, System.Numerics.BigInteger.MinusOne, System.Numerics.BigInteger.Remainder(), System.Span< T >.Slice(), System.Span< T >.ToArray(), and System.value.