Beispiel #1
0
        public string method_4(int radix)
        {
            if (radix > 16)
            {
                throw new ArgumentException("Only radix up to 16 is supported.");
            }
            if (this.IsNaN)
            {
                return("NaN");
            }
            if (this.IsZero)
            {
                return("0");
            }
            StringBuilder stringBuilder = new StringBuilder();
            BigInteger    b             = new BigInteger(radix);

            if (!this.IsZero)
            {
                BigInteger quotient = new BigInteger(this.isNegative, this.length, this.digits);
                while (!quotient.IsZero)
                {
                    BigInteger remainder;
                    BigInteger.smethod_4(quotient, b, out quotient, out remainder);
                    stringBuilder.Insert(0, BigMath.smethod_0(remainder));
                }
            }
            if (this.IsNegative)
            {
                stringBuilder.Insert(0, "-");
            }
            return(stringBuilder.ToString());
        }
Beispiel #2
0
        public string ToString(int radix, int precision)
        {
            if (radix > 16)
            {
                throw new ArgumentException("Only radix up to 16 is supported.");
            }
            if (this.IsNaN)
            {
                return("NaN");
            }
            if (this.IsZero)
            {
                return("0");
            }
            BigInteger quotient1;
            BigInteger remainder1;

            BigInteger.smethod_4(this.numerator, this.denominator, out quotient1, out remainder1);
            StringBuilder stringBuilder = new StringBuilder();
            BigInteger    b             = new BigInteger(radix);

            if (!quotient1.IsZero)
            {
                BigInteger quotient2 = quotient1;
                while (!quotient2.IsZero)
                {
                    BigInteger remainder2;
                    BigInteger.smethod_4(quotient2, b, out quotient2, out remainder2);
                    stringBuilder.Insert(0, BigMath.smethod_0(remainder2));
                }
            }
            if (this.IsNegative)
            {
                stringBuilder.Insert(0, "-");
            }
            if (!remainder1.IsZero)
            {
                if (quotient1.IsZero)
                {
                    BigInteger  numerator   = b * remainder1;
                    BigRational bigRational = new BigRational(numerator, this.denominator);
                    BigInteger  quotient2;
                    BigInteger.smethod_4(bigRational.numerator, bigRational.denominator, out quotient2, out remainder1);
                    int num = 0;
                    while (quotient2.IsZero)
                    {
                        ++num;
                        numerator  *= b;
                        bigRational = new BigRational(numerator, this.denominator);
                        BigInteger.smethod_4(bigRational.numerator, bigRational.denominator, out quotient2, out remainder1);
                    }
                    if (num == 0)
                    {
                        stringBuilder.Append("0.");
                    }
                    stringBuilder.Append(BigMath.smethod_0(quotient2));
                    for (int index = 0; index < precision; ++index)
                    {
                        bigRational = new BigRational(b * remainder1, bigRational.denominator);
                        BigInteger.smethod_4(bigRational.numerator, bigRational.denominator, out quotient2, out remainder1);
                        if (index == 0 && num > 0)
                        {
                            stringBuilder.Append('.');
                        }
                        if (index == precision - 1 && remainder1 * BigInteger.Two >= bigRational.denominator)
                        {
                            quotient2 += BigInteger.One;
                        }
                        stringBuilder.Append(BigMath.smethod_0(quotient2));
                    }
                    if (num > 0)
                    {
                        stringBuilder.Append("E-");
                        stringBuilder.Append((num + 1).ToString());
                    }
                }
                else
                {
                    stringBuilder.Append('.');
                    BigRational bigRational = new BigRational(remainder1, this.denominator, false);
                    for (int index = 0; index < precision; ++index)
                    {
                        bigRational = new BigRational(b * remainder1, bigRational.denominator);
                        BigInteger quotient2;
                        BigInteger.smethod_4(bigRational.numerator, bigRational.denominator, out quotient2, out remainder1);
                        if (index == precision - 1 && remainder1 * BigInteger.Two >= bigRational.denominator)
                        {
                            quotient2 += BigInteger.One;
                        }
                        stringBuilder.Append(BigMath.smethod_0(quotient2));
                    }
                }
            }
            return(stringBuilder.ToString());
        }