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

◆ DoubleToString()

static unsafe string System.Xml.Xsl.XPathConvert.DoubleToString ( double dbl)
inlinestatic

Definition at line 1729 of file XPathConvert.cs.

1730 {
1731 if (IsInteger(dbl, out var value))
1732 {
1733 return value.ToString(CultureInfo.InvariantCulture);
1734 }
1735 if (IsSpecial(dbl))
1736 {
1737 if (double.IsNaN(dbl))
1738 {
1739 return "NaN";
1740 }
1741 if (!(dbl < 0.0))
1742 {
1743 return "Infinity";
1744 }
1745 return "-Infinity";
1746 }
1747 FloatingDecimal floatingDecimal = new FloatingDecimal(dbl);
1748 int num = floatingDecimal.MantissaSize - floatingDecimal.Exponent;
1749 int num2;
1750 if (num > 0)
1751 {
1752 num2 = ((floatingDecimal.Exponent > 0) ? floatingDecimal.Exponent : 0);
1753 }
1754 else
1755 {
1756 num2 = floatingDecimal.Exponent;
1757 num = 0;
1758 }
1759 int num3 = num2 + num + 4;
1760 char* ptr = stackalloc char[num3];
1761 char* ptr2 = ptr;
1762 if (floatingDecimal.Sign < 0)
1763 {
1764 *(ptr2++) = '-';
1765 }
1766 int num4 = floatingDecimal.MantissaSize;
1767 int num5 = 0;
1768 if (num2 != 0)
1769 {
1770 do
1771 {
1772 if (num4 != 0)
1773 {
1774 *(ptr2++) = (char)(floatingDecimal[num5++] | 0x30u);
1775 num4--;
1776 }
1777 else
1778 {
1779 *(ptr2++) = '0';
1780 }
1781 }
1782 while (--num2 != 0);
1783 }
1784 else
1785 {
1786 *(ptr2++) = '0';
1787 }
1788 if (num != 0)
1789 {
1790 *(ptr2++) = '.';
1791 while (num > num4)
1792 {
1793 *(ptr2++) = '0';
1794 num--;
1795 }
1796 while (num4 != 0)
1797 {
1798 *(ptr2++) = (char)(floatingDecimal[num5++] | 0x30u);
1799 num4--;
1800 }
1801 }
1802 return new string(ptr, 0, (int)(ptr2 - ptr));
1803 }
static CultureInfo InvariantCulture
static bool IsInteger(double dbl, out int value)
static bool IsSpecial(double dbl)

References System.Xml.Dictionary, System.Globalization.CultureInfo.InvariantCulture, System.Xml.Xsl.XPathConvert.IsInteger(), System.Xml.Xsl.XPathConvert.IsSpecial(), and System.value.

Referenced by System.Xml.Xsl.Runtime.NumberFormatter.ConvertToDecimal(), System.Xml.Xsl.XPath.XPathQilFactory.ConvertToString(), System.Xml.Xsl.Runtime.NumberFormatter.FormatSequence(), System.Xml.Xsl.Runtime.XsltConvert.ToString(), and System.Xml.Xsl.Runtime.XsltConvert.ToString().