Jurassic.BigInteger.ToString C# (CSharp) Method

ToString() public method

Converts the numeric value of the current BigInteger object to its equivalent string representation.
public ToString ( ) : string
return string
        public override string ToString()
        {
            if (BigInteger.Equals(this, Zero))
                return "0";

            var result = new System.Text.StringBuilder();
            var value = this;
            if (value.Sign < 0)
            {
                result.Append('-');
                value.sign = 1;
            }

            // Overestimate of Floor(Log10(value))
            int log10 = (int)Math.Floor(Log(value, 10)) + 1;

            var divisor = Pow(10, log10);

            // Adjust the values so that Quorum works.
            SetupQuorum(ref value, ref divisor);

            // Check for overestimate of log10.
            if (BigInteger.Compare(divisor, value) > 0)
            {
                value = BigInteger.MultiplyAdd(value, 10, 0);
                log10--;
            }

            for (int i = 0; i <= log10; i ++)
            {
                // value = value / divisor
                int digit = Quorem(ref value, divisor);

                // Append the digit.
                result.Append((char)(digit + '0'));

                // value = value * 10;
                value = BigInteger.MultiplyAdd(value, 10, 0);
            }
            return result.ToString();
        }