Exemple #1
0
        public static IdleCurrency Multiply(IdleCurrency left, IdleCurrency right)
        {
            IdleCurrency bd = new IdleCurrency(
                left.Value * right.Value,
                left.Exp + right.Exp);

            bd.Simplify();
            return(bd);
        }
Exemple #2
0
        public static IdleCurrency Divide(IdleCurrency dividend, IdleCurrency divisor)
        {
            if (divisor == 0)
            {
                throw new DivideByZeroException();
            }

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

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