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

◆ VarDecMod()

static void System.Decimal.DecCalc.VarDecMod ( ref DecCalc d1,
ref DecCalc d2 )
inlinestaticpackage

Definition at line 1767 of file Decimal.cs.

1768 {
1769 if ((d2.ulo | d2.umid | d2.uhi) == 0)
1770 {
1771 throw new DivideByZeroException();
1772 }
1773 if ((d1.ulo | d1.umid | d1.uhi) == 0)
1774 {
1775 return;
1776 }
1777 d2.uflags = (d2.uflags & 0x7FFFFFFFu) | (d1.uflags & 0x80000000u);
1778 int num = VarDecCmpSub(in Unsafe.As<DecCalc, decimal>(ref d1), in Unsafe.As<DecCalc, decimal>(ref d2));
1779 if (num == 0)
1780 {
1781 d1.ulo = 0u;
1782 d1.umid = 0u;
1783 d1.uhi = 0u;
1784 if (d2.uflags > d1.uflags)
1785 {
1786 d1.uflags = d2.uflags;
1787 }
1788 }
1789 else
1790 {
1791 if ((int)((uint)num ^ (d1.uflags & 0x80000000u)) < 0)
1792 {
1793 return;
1794 }
1795 int num2 = (sbyte)(d1.uflags - d2.uflags >> 16);
1796 if (num2 > 0)
1797 {
1798 do
1799 {
1800 uint num3 = ((num2 >= 9) ? 1000000000u : s_powers10[num2]);
1801 ulong num4 = UInt32x32To64(d2.Low, num3);
1802 d2.Low = (uint)num4;
1803 num4 >>= 32;
1804 num4 += (d2.Mid + ((ulong)d2.High << 32)) * num3;
1805 d2.Mid = (uint)num4;
1806 d2.High = (uint)(num4 >> 32);
1807 }
1808 while ((num2 -= 9) > 0);
1809 num2 = 0;
1810 }
1811 do
1812 {
1813 if (num2 < 0)
1814 {
1815 d1.uflags = d2.uflags;
1816 Unsafe.SkipInit<Buf12>(out var value);
1817 value.Low64 = d1.Low64;
1818 value.U2 = d1.High;
1819 uint num6;
1820 do
1821 {
1822 int num5 = SearchScale(ref value, 28 + num2);
1823 if (num5 == 0)
1824 {
1825 break;
1826 }
1827 num6 = ((num5 >= 9) ? 1000000000u : s_powers10[num5]);
1828 num2 += num5;
1829 ulong num7 = UInt32x32To64(value.U0, num6);
1830 value.U0 = (uint)num7;
1831 num7 >>= 32;
1833 }
1834 while (num6 == 1000000000 && num2 < 0);
1835 d1.Low64 = value.Low64;
1836 d1.High = value.U2;
1837 }
1838 if (d1.High == 0)
1839 {
1840 d1.Low64 %= d2.Low64;
1841 break;
1842 }
1843 if ((d2.High | d2.Mid) == 0)
1844 {
1845 uint low = d2.Low;
1846 ulong num8 = ((ulong)d1.High << 32) | d1.Mid;
1847 num8 = (num8 % low << 32) | d1.Low;
1848 d1.Low64 = num8 % low;
1849 d1.High = 0u;
1850 continue;
1851 }
1853 break;
1854 }
1855 while (num2 < 0);
1856 }
1857 }
static readonly uint[] s_powers10
Definition Decimal.cs:205
static int SearchScale(ref Buf12 bufQuo, int scale)
Definition Decimal.cs:635
static unsafe void VarDecModFull(ref DecCalc d1, ref DecCalc d2, int scale)
Definition Decimal.cs:1859
static ulong UInt32x32To64(uint a, uint b)
Definition Decimal.cs:300
static int VarDecCmpSub(in decimal d1, in decimal d2)
Definition Decimal.cs:1067

References System.Runtime.Serialization.Dictionary, System.Decimal.DecCalc.Buf12.Low64, System.Decimal.DecCalc.s_powers10, System.Decimal.DecCalc.SearchScale(), System.Decimal.DecCalc.UInt32x32To64(), System.value, System.Decimal.DecCalc.VarDecCmpSub(), and System.Decimal.DecCalc.VarDecModFull().

Referenced by System.Decimal.operator%(), and System.Decimal.Remainder().