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

◆ VarDecDiv()

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

Definition at line 1562 of file Decimal.cs.

1563 {
1564 Unsafe.SkipInit<Buf12>(out var value);
1565 int scale = (sbyte)(d1.uflags - d2.uflags >> 16);
1566 bool flag = false;
1567 uint low;
1568 uint num;
1569 Buf16 value2;
1570 ulong num7;
1571 Buf12 value3;
1572 uint num6;
1573 if ((d2.High | d2.Mid) == 0)
1574 {
1575 low = d2.Low;
1576 if (low == 0)
1577 {
1578 throw new DivideByZeroException();
1579 }
1580 value.Low64 = d1.Low64;
1581 value.U2 = d1.High;
1582 num = Div96By32(ref value, low);
1583 while (true)
1584 {
1585 int num2;
1586 if (num == 0)
1587 {
1588 if (scale >= 0)
1589 {
1590 break;
1591 }
1592 num2 = Math.Min(9, -scale);
1593 }
1594 else
1595 {
1596 flag = true;
1597 if (scale == 28 || (num2 = SearchScale(ref value, scale)) == 0)
1598 {
1599 goto IL_0090;
1600 }
1601 }
1602 uint num3 = s_powers10[num2];
1603 scale += num2;
1604 if (IncreaseScale(ref value, num3) == 0)
1605 {
1606 ulong num4 = UInt32x32To64(num, num3);
1607 uint num5 = (uint)(num4 / low);
1608 num = (uint)(int)num4 - num5 * low;
1609 if (!Add32To96(ref value, num5))
1610 {
1611 scale = OverflowUnscale(ref value, scale, num != 0);
1612 break;
1613 }
1614 continue;
1615 }
1616 goto IL_04ab;
1617 }
1618 }
1619 else
1620 {
1621 num6 = d2.High;
1622 if (num6 == 0)
1623 {
1624 num6 = d2.Mid;
1625 }
1627 Unsafe.SkipInit<Buf16>(out value2);
1629 value2.High64 = d1.Mid + ((ulong)d1.High << 32) >> 32 - num2;
1630 num7 = d2.Low64 << num2;
1631 if (d2.High == 0)
1632 {
1633 value.U2 = 0u;
1634 value.U1 = Div96By64(ref *(Buf12*)(&value2.U1), num7);
1635 value.U0 = Div96By64(ref *(Buf12*)(&value2), num7);
1636 while (true)
1637 {
1638 if (value2.Low64 == 0L)
1639 {
1640 if (scale >= 0)
1641 {
1642 break;
1643 }
1644 num2 = Math.Min(9, -scale);
1645 }
1646 else
1647 {
1648 flag = true;
1649 if (scale == 28 || (num2 = SearchScale(ref value, scale)) == 0)
1650 {
1651 goto IL_01e8;
1652 }
1653 }
1654 uint num3 = s_powers10[num2];
1655 scale += num2;
1656 if (IncreaseScale(ref value, num3) == 0)
1657 {
1658 IncreaseScale64(ref *(Buf12*)(&value2), num3);
1659 num6 = Div96By64(ref *(Buf12*)(&value2), num7);
1660 if (!Add32To96(ref value, num6))
1661 {
1662 scale = OverflowUnscale(ref value, scale, value2.Low64 != 0);
1663 break;
1664 }
1665 continue;
1666 }
1667 goto IL_04ab;
1668 }
1669 }
1670 else
1671 {
1672 Unsafe.SkipInit<Buf12>(out value3);
1674 value3.U2 = (uint)(d2.Mid + ((ulong)d2.High << 32) >> 32 - num2);
1676 value.U2 = 0u;
1677 while (true)
1678 {
1679 if ((value2.Low64 | value2.U2) == 0L)
1680 {
1681 if (scale >= 0)
1682 {
1683 break;
1684 }
1685 num2 = Math.Min(9, -scale);
1686 }
1687 else
1688 {
1689 flag = true;
1690 if (scale == 28 || (num2 = SearchScale(ref value, scale)) == 0)
1691 {
1692 goto IL_0302;
1693 }
1694 }
1695 uint num3 = s_powers10[num2];
1696 scale += num2;
1697 if (IncreaseScale(ref value, num3) == 0)
1698 {
1699 value2.U3 = IncreaseScale(ref *(Buf12*)(&value2), num3);
1701 if (!Add32To96(ref value, num6))
1702 {
1703 scale = OverflowUnscale(ref value, scale, (value2.Low64 | value2.High64) != 0);
1704 break;
1705 }
1706 continue;
1707 }
1708 goto IL_04ab;
1709 }
1710 }
1711 }
1712 goto IL_03f3;
1713 IL_0302:
1714 if ((int)value2.U2 >= 0)
1715 {
1716 num6 = value2.U1 >> 31;
1717 value2.Low64 <<= 1;
1718 value2.U2 = (value2.U2 << 1) + num6;
1719 if (value2.U2 <= value3.U2 && (value2.U2 != value3.U2 || (value2.Low64 <= value3.Low64 && (value2.Low64 != value3.Low64 || (value.U0 & 1) == 0))))
1720 {
1721 goto IL_03f3;
1722 }
1723 }
1724 goto IL_046a;
1725 IL_03f3:
1726 if (flag)
1727 {
1728 uint low2 = value.U0;
1729 ulong high = value.High64;
1730 Unscale(ref low2, ref high, ref scale);
1731 d1.Low = low2;
1732 d1.Mid = (uint)high;
1733 d1.High = (uint)(high >> 32);
1734 }
1735 else
1736 {
1737 d1.Low64 = value.Low64;
1738 d1.High = value.U2;
1739 }
1740 d1.uflags = ((d1.uflags ^ d2.uflags) & 0x80000000u) | (uint)(scale << 16);
1741 return;
1742 IL_046a:
1743 if (++value.Low64 == 0L && ++value.U2 == 0)
1744 {
1745 scale = OverflowUnscale(ref value, scale, sticky: true);
1746 }
1747 goto IL_03f3;
1748 IL_04ab:
1749 Number.ThrowOverflowException(TypeCode.Decimal);
1750 return;
1751 IL_01e8:
1752 ulong low3 = value2.Low64;
1753 if ((long)low3 >= 0L && (low3 <<= 1) <= num7 && (low3 != num7 || (value.U0 & 1) == 0))
1754 {
1755 goto IL_03f3;
1756 }
1757 goto IL_046a;
1758 IL_0090:
1759 num6 = num << 1;
1760 if (num6 >= num && (num6 < low || (num6 <= low && (value.U0 & 1) == 0)))
1761 {
1762 goto IL_03f3;
1763 }
1764 goto IL_046a;
1765 }
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 int SearchScale(ref Buf12 bufQuo, int scale)
Definition Decimal.cs:635
static uint Div128By96(ref Buf16 bufNum, ref Buf12 bufDen)
Definition Decimal.cs:444
static uint IncreaseScale(ref Buf12 bufNum, uint power)
Definition Decimal.cs:491
static void IncreaseScale64(ref Buf12 bufNum, uint power)
Definition Decimal.cs:504
static void Unscale(ref uint low, ref ulong high64, ref int scale)
Definition Decimal.cs:370
static bool Add32To96(ref Buf12 bufNum, uint value)
Definition Decimal.cs:704
static int OverflowUnscale(ref Buf12 bufQuo, int scale, bool sticky)
Definition Decimal.cs:618
static uint Div96By32(ref Buf12 bufNum, uint den)
Definition Decimal.cs:331
static ulong UInt32x32To64(uint a, uint b)
Definition Decimal.cs:300

References System.Decimal.DecCalc.Add32To96(), System.Runtime.Serialization.Dictionary, System.Decimal.DecCalc.Div128By96(), System.Decimal.DecCalc.Div96By32(), System.Decimal.DecCalc.Div96By64(), System.Decimal.DecCalc.IncreaseScale(), System.Decimal.DecCalc.IncreaseScale64(), System.L, System.Numerics.BitOperations.LeadingZeroCount(), System.Math.Min(), System.Decimal.DecCalc.OverflowUnscale(), System.Decimal.DecCalc.s_powers10, System.Decimal.DecCalc.SearchScale(), System.Number.ThrowOverflowException(), System.Decimal.DecCalc.UInt32x32To64(), System.Decimal.DecCalc.Unscale(), and System.value.

Referenced by System.Decimal.Divide(), and System.Decimal.operator/().