示例#1
0
 internal static BigInteger FindPowerOfTenFromBig(BigInteger bigintExponent)
 {
     int sign=bigintExponent.Sign;
       if(sign<0)return BigInteger.Zero;
       if (sign == 0) return BigInteger.One;
       if (bigintExponent.CompareTo(BigInt36) <= 0) {
     return FindPowerOfTen((int)bigintExponent);
       }
       FastInteger intcurexp = FastInteger.FromBig(bigintExponent);
       BigInteger mantissa = BigInteger.One;
       BigInteger bigpow = BigInteger.Zero;
       while (intcurexp.Sign > 0) {
     if (intcurexp.CompareToInt(18) <= 0) {
       bigpow = FindPowerOfTen(intcurexp.AsInt32());
       mantissa *= (BigInteger)bigpow;
       break;
     } else if (intcurexp.CompareToInt(9999999) <= 0) {
       int val = intcurexp.AsInt32();
       bigpow = FindPowerOfFive(val);
       bigpow <<= val;
       mantissa *= (BigInteger)bigpow;
       break;
     } else {
       if (bigpow.IsZero) {
     bigpow = FindPowerOfFive(9999999);
     bigpow <<= 9999999;
       }
       mantissa *= bigpow;
       intcurexp.AddInt(-9999999);
     }
       }
       return mantissa;
 }
示例#2
0
 /// <summary> </summary>
 /// <param name='exponentMin'>A BigInteger object.</param>
 /// <param name='exponentMax'>A BigInteger object.</param>
 /// <returns>A PrecisionContext object.</returns>
 public PrecisionContext WithExponentRange(BigInteger exponentMin, BigInteger exponentMax) {
   if((exponentMin)==null)throw new ArgumentNullException("exponentMin");
   if(exponentMin.CompareTo(exponentMax)>0)
     throw new ArgumentException("exponentMin greater than exponentMax");
   PrecisionContext pc = this.Copy();
   pc.hasExponentRange=true;
   pc.exponentMin=exponentMin;
   pc.exponentMax=exponentMax;
   return pc;
 }
示例#3
0
 private static decimal BigIntegerToDecimal(BigInteger bi)
 {
     if(bi.Sign<0){
     if(bi.CompareTo(DecimalMinValue)<0)
       throw new OverflowException();
     bi=-bi;
     return EncodeDecimal(bi,0,true);
       }
       if(bi.CompareTo(DecimalMaxValue)>0)
     throw new OverflowException();
       return EncodeDecimal(bi,0,false);
 }
示例#4
0
 /// <summary> </summary>
 /// <param name='exponent'>A BigInteger object.</param>
 /// <returns>A Boolean object.</returns>
 public bool ExponentWithinRange(BigInteger exponent){
   if((exponent)==null)throw new ArgumentNullException("exponent");
   if(!this.HasExponentRange)
     return true;
   if(bigintPrecision.IsZero){
     // Only check EMax, since with an unlimited
     // precision, any exponent less than EMin will exceed EMin if
     // the mantissa is the right size
     return exponent.CompareTo(this.EMax)<=0;
   } else {
     BigInteger bigint=exponent;
     bigint+=(BigInteger)bigintPrecision;
     bigint-=BigInteger.One;
     if(bigint.CompareTo(this.EMin)<0)
       return false;
     if(exponent.CompareTo(this.EMax)>0)
       return false;
     return true;
   }
 }