Exemplo n.º 1
0
        public static BiggerDouble Multiply(BiggerDouble left, BiggerDouble right)
        {
            BiggerDouble bd = new BiggerDouble(
                left.Value * right.Value,
                left.Exp + right.Exp);

            bd.Simplify();
            return(bd);
        }
Exemplo n.º 2
0
        public static BiggerDouble Divide(BiggerDouble dividend, BiggerDouble divisor)
        {
            if (divisor == 0)
            {
                throw new DivideByZeroException();
            }

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

            bd.Simplify();
            return(bd);
        }
Exemplo n.º 3
0
 public static BiggerDouble operator+(BiggerDouble a, BiggerDouble b)
 {
     if (a.Exp == b.Exp)
     {
         BiggerDouble m = new BiggerDouble();
         m.Exp   = a.Exp;
         m.Value = a.Value + b.Value;
         m.Simplify();
         return(m);
     }
     else if (a.Exp > b.Exp)
     {
         // a is bigger
         Int256 deltaExp = a.Exp - b.Exp;
         if (deltaExp <= 16)
         {
             double       bX = b.Value / Math.Pow(10, (double)deltaExp);
             BiggerDouble m  = new BiggerDouble();
             m.Exp   = a.Exp;
             m.Value = a.Value + bX;
             m.Simplify();
             return(m);
         }
         else
         {
             return(a);
         }
     }
     else
     {
         // b is bigger
         Int256 deltaExp = b.Exp - a.Exp;
         if (deltaExp <= 16)
         {
             double       aX = a.Value / Math.Pow(10, (double)deltaExp);
             BiggerDouble m  = new BiggerDouble();
             m.Exp   = b.Exp;
             m.Value = b.Value + aX;
             m.Simplify();
             return(m);
         }
         else
         {
             return(b);
         }
     }
 }