Пример #1
0
        public static BigDouble Multiply(BigDouble left, BigDouble right)
        {
            BigDouble bd = new BigDouble(
                left.Value * right.Value,
                left.Exp + right.Exp);

            bd.Simplify();
            return(bd);
        }
Пример #2
0
        public static BigDouble Divide(BigDouble dividend, BigDouble divisor)
        {
            if (divisor == 0)
            {
                throw new DivideByZeroException();
            }

            BigDouble bd = new BigDouble(
                dividend.Value / divisor.Value,
                dividend.Exp - divisor.Exp);

            bd.Simplify();
            return(bd);
        }
Пример #3
0
 public static BigDouble operator+(BigDouble a, BigDouble b)
 {
     if (a.Exp == b.Exp)
     {
         BigDouble m = new BigDouble();
         m.Exp   = a.Exp;
         m.Value = a.Value + b.Value;
         m.Simplify();
         return(m);
     }
     else if (a.Exp > b.Exp)
     {
         // a is bigger
         ulong deltaExp = a.Exp - b.Exp;
         if (deltaExp <= 16)
         {
             double    bX = b.Value / Math.Pow(10, deltaExp);
             BigDouble m  = new BigDouble();
             m.Exp   = a.Exp;
             m.Value = a.Value + bX;
             m.Simplify();
             return(m);
         }
         else
         {
             return(a);
         }
     }
     else
     {
         // b is bigger
         ulong deltaExp = b.Exp - a.Exp;
         if (deltaExp <= 16)
         {
             double    aX = a.Value / Math.Pow(10, deltaExp);
             BigDouble m  = new BigDouble();
             m.Exp   = b.Exp;
             m.Value = b.Value + aX;
             m.Simplify();
             return(m);
         }
         else
         {
             return(b);
         }
     }
 }