Exemplo n.º 1
0
        public static double RoundWithPrecision(this double value, double precision)
        {
            if (precision == 0.0 || value == 0.0)
            {
                return(value);
            }
            int num1 = DoubleHelper.Log10(Math.Abs(value));
            int exp  = DoubleHelper.Log10(Math.Abs(precision));
            int num2 = num1 - exp;

            if (num2 > 16)
            {
                return(value);
            }
            if (num2 < 0)
            {
                return(0.0);
            }
            double num3 = DoubleHelper.Pow10(exp);

            if (num3 == 0.0)
            {
                return(value);
            }
            double num4 = (double)(long)Math.Round(value / num3) * num3;

            if (0 > exp && exp > -16)
            {
                return(Math.Round(num4, -exp));
            }
            return(num4);
        }
Exemplo n.º 2
0
        public static double GetPrecision(int digits, params double[] values)
        {
            int num1 = int.MinValue;

            for (int index = 0; index < values.Length; ++index)
            {
                double val = Math.Abs(values[index]);
                if (val != 0.0)
                {
                    int num2 = DoubleHelper.Log10(val);
                    if (num2 > num1)
                    {
                        num1 = num2;
                    }
                }
            }
            if (num1 > int.MinValue)
            {
                return(DoubleHelper.Pow10(Math.Max(num1 - digits, -DoubleHelper.DoubleNegativePowers.Length + 1)));
            }
            return(0.0);
        }
Exemplo n.º 3
0
 public DoubleR10(double value)
 {
     if (value > 0.0)
     {
         long num1 = (long)value;
         if (value < 1E+18 && (double)num1 == value)
         {
             this.M = num1;
             this.E = 0;
         }
         else
         {
             if (value < 100000000000000.0)
             {
                 double num2 = value * 10000.0;
                 long   num3 = (long)num2;
                 if ((double)num3 == num2)
                 {
                     this.M = num3;
                     this.E = -4;
                     return;
                 }
             }
             if (value <= double.MaxValue)
             {
                 int    exp  = DoubleHelper.Log10(value) - 14;
                 double num2 = DoubleHelper.Pow10(exp);
                 this.M = (long)Math.Round(value / num2);
                 this.E = exp;
             }
             else
             {
                 this = DoubleR10.PositiveInfinity;
             }
         }
     }
     else if (value < 0.0)
     {
         long num1 = (long)value;
         if (value > -1E+18 && (double)num1 == value)
         {
             this.M = num1;
             this.E = 0;
         }
         else
         {
             if (value > -100000000000000.0)
             {
                 double num2 = value * 10000.0;
                 long   num3 = (long)num2;
                 if ((double)num3 == num2)
                 {
                     this.M = num3;
                     this.E = -4;
                     return;
                 }
             }
             if (value >= double.MinValue)
             {
                 int    exp  = DoubleHelper.Log10(-value) - 14;
                 double num2 = DoubleHelper.Pow10(exp);
                 this.M = (long)Math.Round(value / num2);
                 this.E = exp;
             }
             else
             {
                 this = DoubleR10.NegativeInfinity;
             }
         }
     }
     else if (value == 0.0)
     {
         this = DoubleR10.Zero;
     }
     else
     {
         this = DoubleR10.NaN;
     }
 }