Exemple #1
0
        public Money Reduce(Bank bank, string to)
        {
            var amount = Augend.Reduce(bank, to).Amount +
                         Addend.Reduce(bank, to).Amount;

            return(new Money(amount, to));
        }
    /* Operators */
    public static MiniFloat operator +(MiniFloat Augend, MiniFloat Addend)
    {
        MiniFloat m = Augend.Copy();
        MiniFloat n = Addend.Copy();

        m.Mantissa = '1' + m.Mantissa;
        n.Mantissa = '1' + n.Mantissa;
        Normalize(ref m, ref n);

        if (m.Signbit == '0' && n.Signbit == '0')
        {
            return(add(m, n));
        }
        else if ((m.Signbit == '1' && n.Signbit == '0') || (n.Signbit == '1' && m.Signbit == '0'))
        {
            if (m.Mantissa > n.Mantissa)
            {
                return(sub(m, n));
            }
            else if (n.Mantissa > m.Mantissa)
            {
                return(sub(n, m));
            }
            else /* Equal */ return {
                (new MiniFloat());                   //Zero
            }
        }
        else     //Both are negative
        {
            MiniFloat r = add(m, n);
            r.Signbit = '1';
            return(r);
        }
    }
Exemple #3
0
        public override Money reduce(Bank bank, string to)
        {
            int amount =
                Augend.reduce(bank, to).Amount + Addend.reduce(bank, to).Amount;

            return(new Money(amount, to));
        }
        public Money Reduce(Bank bank, string to)
        {
            var reducedAugend = Augend.Reduce(bank, to);
            var reducedAddend = Addend.Reduce(bank, to);
            var amount        = reducedAugend.Amount + reducedAddend.Amount;

            return(new Money(amount, to));
        }
Exemple #5
0
        public Money Reduce(Bank bank, string targetCurrency)
        {
            var reducedAugend = Augend.Reduce(bank, targetCurrency);
            var reducedAddend = Addend.Reduce(bank, targetCurrency);
            var totalAmount   = reducedAugend.Amount + reducedAddend.Amount;

            return(new Money(totalAmount, targetCurrency));
        }
Exemple #6
0
        public Money Reduce(Bank bank, string to)
        {
            // 3. Implement reduction. This was not done after earlier implementation.
            //int amount = Augend.Amount + Addend.Amount;
            //return new Money(amount, to);
            int amount = Augend.Reduce(bank, to).Amount +
                         Addend.Reduce(bank, to).Amount;

            return(new Money(amount, to));
        }
Exemple #7
0
    /* -- End of Operators for Concatenation -- */

    public static Binary operator +(Binary Augend, Binary Addend)
    {
        Binary m = Augend.Copy();
        Binary n = Addend.Copy();

        /* Normalize to the longest one */
        int l;

        if (m.Length > n.Length)
        {
            l = m.Length;
            for (int i = n.Length; i < m.Length; i++)
            {
                n = '0' + n;
            }
        }
        else if (m.Length < n.Length)
        {
            l = n.Length;
            for (int i = m.Length; i < n.Length; i++)
            {
                m = '0' + m;
            }
        }
        else
        {
            l = m.Length;
        }

        Binary c = new Binary(l);

        for (int i = l - 1; i >= 0; i--)
        {
            int x = MainClass.ValueOf(m[i]) + MainClass.ValueOf(n[i]) + MainClass.ValueOf(c[i]);
            c[i] = MainClass.Character(x);
            if (c[i] == '2' || c[i] == '3')
            {
                c[i] = (c[i] == '2' ? '0' : '1');
                if (i - 1 < 0)   //If it's the last one...
                {
                    c = '1' + c;
                }
                else
                {
                    c[i - 1] = '1';
                }
            }
        }
        return(c);
    }
 public Expression Times(int multiplier)
 {
     return(new Sum(Augend.Times(multiplier), Addend.Times(multiplier)));
 }
Exemple #9
0
 public MoneyExpression Times(int multiplier) => new SumExpression(Augend.Times(multiplier), Addend.Times(multiplier));
Exemple #10
0
 public IExpression Times(int multiplier) => new Sum(Augend.Times(multiplier), Addend.Times(multiplier));
Exemple #11
0
 public Expression Times(double factor)
 {
     return(new Sum(Augend.Times(factor), Addend.Times(factor)));
 }
Exemple #12
0
 public Money Reduce(IBank bank, string to)
 {
     return(new Money(Augend.Reduce(bank, to).amount + Addend.Reduce(bank, to).amount, to));
 }
Exemple #13
0
 public override Expression times(int multiplier)
 {
     return(new Sum(Augend.times(multiplier), Addend.times(multiplier)));
 }
Exemple #14
0
 public IExpression Times(int multiplier)
 {
     // 4. Implement Times method.
     return(new Sum(Augend.Times(multiplier), Addend.Times(multiplier)));
 }