Exemplo n.º 1
0
        public override string /*!*/ ToString()
        {
            Contract.Ensures(Contract.Result <string>() != null);
            String sigSize = significandSize.ToString();
            String expSize = exponentSize.ToString();

            if (value == "")
            {
                String sig = significand.ToString();
                String exp = exponent.ToString();
                return(String.Format("{0}{1}e{2}f{3}e{4}", isNeg ? "-" : "", sig, exp, sigSize, expSize));
            }
            return(String.Format("0{0}{1}e{2}", value, sigSize, expSize));
        }
Exemplo n.º 2
0
        public String ToDecimalString(int maxDigits)
        {
            string s      = this.mantissa.ToString();
            int    digits = (this.mantissa >= 0) ? s.Length : s.Length - 1;
            BIM    max    = BIM.Pow(10, maxDigits);
            BIM    min    = -max;

            if (this.exponent >= 0)
            {
                if (maxDigits < digits || maxDigits - digits < this.exponent)
                {
                    return(String.Format("{0}.0", (this.mantissa >= 0) ? max.ToString() : min.ToString()));
                }
                else
                {
                    return(String.Format("{0}{1}.0", s, new string('0', this.exponent)));
                }
            }
            else
            {
                int exp = -this.exponent;

                if (exp < digits)
                {
                    int intDigits = digits - exp;
                    if (maxDigits < intDigits)
                    {
                        return(String.Format("{0}.0", (this.mantissa >= 0) ? max.ToString() : min.ToString()));
                    }
                    else
                    {
                        int fracDigits = Math.Min(maxDigits, digits - intDigits);
                        return(String.Format("{0}.{1}", s.Substring(0, intDigits), s.Substring(intDigits, fracDigits)));
                    }
                }
                else
                {
                    int fracDigits = Math.Min(maxDigits, digits);
                    return(String.Format("0.{0}{1}", new string('0', exp - fracDigits), s.Substring(0, fracDigits)));
                }
            }
        }
Exemplo n.º 3
0
 public static BigFloat FromBigInt(BIM v, int significandSize, int exponentSize)
 {
     return(new BigFloat(v.ToString(), significandSize, exponentSize));
 }
Exemplo n.º 4
0
 public static BigFloat FromBigInt(BIM v)
 {
     return(new BigFloat(v.ToString(), 24, 8));
 }
Exemplo n.º 5
0
 public static BigFloat FromBigInt(BIM v, int significandSize, int exponentSize)
 {
   return new BigFloat(v.ToString(), significandSize, exponentSize);
 }
Exemplo n.º 6
0
 public static BigFloat FromBigInt(BIM v) {
   return new BigFloat(v.ToString(), 24, 8);
 }
Exemplo n.º 7
0
 public string ToDecimalString()
 {
     Contract.Ensures(Contract.Result <string>() != null);
     return(value == "" ? String.Format("{0}x2^{1}", significand.ToString(), Exponent.ToString()) : value);
 }