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

◆ VarDecModFull()

static unsafe void System.Decimal.DecCalc.VarDecModFull ( ref DecCalc d1,
ref DecCalc d2,
int scale )
inlinestaticprivate

Definition at line 1859 of file Decimal.cs.

1860 {
1861 uint num = d2.High;
1862 if (num == 0)
1863 {
1864 num = d2.Mid;
1865 }
1867 Unsafe.SkipInit<Buf28>(out var value);
1869 value.Buf24.Mid64 = d1.Mid + ((ulong)d1.High << 32) >> 32 - num2;
1870 uint num3 = 3u;
1871 while (scale < 0)
1872 {
1873 uint b = ((scale <= -9) ? 1000000000u : s_powers10[-scale]);
1874 uint* ptr = (uint*)(&value);
1875 ulong num4 = UInt32x32To64(value.Buf24.U0, b);
1876 value.Buf24.U0 = (uint)num4;
1877 for (int i = 1; i <= num3; i++)
1878 {
1879 num4 >>= 32;
1880 num4 += UInt32x32To64(ptr[i], b);
1881 ptr[i] = (uint)num4;
1882 }
1883 if (num4 > int.MaxValue)
1884 {
1885 ptr[++num3] = (uint)(num4 >> 32);
1886 }
1887 scale += 9;
1888 }
1889 if (d2.High == 0)
1890 {
1891 ulong den = d2.Low64 << num2;
1892 switch (num3)
1893 {
1894 case 6u:
1895 Div96By64(ref *(Buf12*)(&value.Buf24.U4), den);
1896 goto case 5u;
1897 case 5u:
1898 Div96By64(ref *(Buf12*)(&value.Buf24.U3), den);
1899 goto case 4u;
1900 case 4u:
1901 Div96By64(ref *(Buf12*)(&value.Buf24.U2), den);
1902 break;
1903 }
1904 Div96By64(ref *(Buf12*)(&value.Buf24.U1), den);
1905 Div96By64(ref *(Buf12*)(&value), den);
1907 d1.High = 0u;
1908 return;
1909 }
1910 Unsafe.SkipInit<Buf12>(out var value2);
1912 value2.U2 = (uint)(d2.Mid + ((ulong)d2.High << 32) >> 32 - num2);
1913 switch (num3)
1914 {
1915 case 6u:
1916 Div128By96(ref *(Buf16*)(&value.Buf24.U3), ref value2);
1917 goto case 5u;
1918 case 5u:
1919 Div128By96(ref *(Buf16*)(&value.Buf24.U2), ref value2);
1920 goto case 4u;
1921 case 4u:
1922 Div128By96(ref *(Buf16*)(&value.Buf24.U1), ref value2);
1923 break;
1924 }
1925 Div128By96(ref *(Buf16*)(&value), ref value2);
1926 d1.Low64 = (value.Buf24.Low64 >> num2) + ((ulong)value.Buf24.U2 << 32 - num2 << 32);
1928 }
static int LeadingZeroCount(uint value)
static uint Div96By64(ref Buf12 bufNum, ulong den)
Definition Decimal.cs:390
static readonly uint[] s_powers10
Definition Decimal.cs:205
static uint Div128By96(ref Buf16 bufNum, ref Buf12 bufDen)
Definition Decimal.cs:444
static ulong UInt32x32To64(uint a, uint b)
Definition Decimal.cs:300
const decimal MaxValue
Definition Decimal.cs:2067

References System.Runtime.Serialization.Dictionary, System.Decimal.DecCalc.Div128By96(), System.Decimal.DecCalc.Div96By64(), System.Numerics.BitOperations.LeadingZeroCount(), System.Decimal.MaxValue, System.Decimal.DecCalc.s_powers10, System.Decimal.DecCalc.UInt32x32To64(), and System.value.

Referenced by System.Decimal.DecCalc.VarDecMod().