Example #1
0
        protected sealed override void Calculate()
        {
            switch (BaseType)
            {
            case BaseValueType.Double: {
                _SetDouble(Minuend.GetDouble() - Subtrahend.GetDouble());
                break;
            }

            case BaseValueType.Single: {
                _SetSingle(Minuend.GetSingle() - Subtrahend.GetSingle());
                break;
            }

            case BaseValueType.Int64: {
                _SetInt64(Minuend.GetInt64() - Subtrahend.GetInt64());
                break;
            }

            case BaseValueType.Int32:
            default: {
                _SetInt32(Minuend.GetInt32() - Subtrahend.GetInt32());
                break;
            }
            }
        }
Example #2
0
 public bool Equals(DifferenceOfPaths <TVertex> otherDifference)
 {
     if (otherDifference is null)
     {
         return(false);
     }
     return(Minuend.Equals(otherDifference.Minuend) && Subtrahend.Equals(otherDifference.Subtrahend));
 }
Example #3
0
    public static MiniFloat operator -(MiniFloat Minuend, MiniFloat Subtrahend)
    {
        MiniFloat m = Minuend.Copy();
        MiniFloat n = Subtrahend.Copy();

        /* To subtract, you add the negative */
        n.Signbit = (n.Signbit == '0') ? '1' : '0'; //flip dat bit
        return(m + n);                              //+ operator deals with the signbit stuff
    }
Example #4
0
 public override string ToString()
 {
     return("(" + Minuend.ToString() + " - " + Subtrahend.ToString() + ")");
 }
Example #5
0
 public override double Evaluate(VariableReplacements replacements)
 {
     return(Minuend.Evaluate(replacements) - Subtrahend.Evaluate(replacements));
 }
Example #6
0
    public static Binary operator -(Binary Minuend, Binary Subtrahend)
    {
        Binary m = Minuend.Copy();
        Binary n = Subtrahend.Copy();

        void Borrow(ref Binary x, int p /* The index that caused a problem & must become a two */)
        {
            while (x[p] != '1' && x[p] != '2')
            {
                for (int i = p - 1 /**/; i >= 0; i--)
                {
                    if (x[i] == '1')
                    {
                        x[i]     = '0';
                        x[i + 1] = '2';
                        break;
                    }
                    else if (x[i] == '2')
                    {
                        x[i]     = '1';
                        x[i + 1] = '2';
                        break;
                    }
                }
            }
        }

        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--)
        {
            bool flag = true;
            do
            {
                int x = MainClass.ValueOf(m[i]) - MainClass.ValueOf(n[i]);
                if (x < 0)
                {
                    if (i - 1 < 0)
                    {
                        throw new BinaryUnderFlowException("Cannot borrow in last column, underflow error.");
                    }
                    else
                    {
                        Borrow(ref m, i);
                    }
                }
                else
                {
                    flag = false;
                    c[i] = MainClass.Character(x);
                }
            } while (flag);
        }

        return(c);
    }

    public static Binary operator *(Binary Multiplicand, Binary Multiplier)
    {
        Binary m = Multiplicand.Copy();
        Binary n = Multiplier.Copy();

        Binary[] partials = new Binary[n.Length]; // List of the partial sums
        for (int i = 0; i < partials.Length; i++)
        {
            partials[i] = new Binary();
        }

        for (int i = n.Length - 1; i >= 0; i--)
        {
            for (int k = 0; k < n.Length - (i + 1); k++)
            {
                partials[i] += '0';
            }
            for (int j = m.Length - 1; j >= 0; j--)
            {
                partials[i] += Convert.ToString(MainClass.ValueOf(n[i]) * MainClass.ValueOf(m[j]));
            }
            partials[i].Reverse();
        }

        Binary c = new Binary();

        for (int i = 0; i < partials.Length; i++)
        {
            c += partials[i];
        }

        return(c);
    }

    public static Binary operator *(int Multiplicand, Binary Multiplier) => new Binary(BaseChange(Multiplicand, 10, 2)) * Multiplier;
    public static Binary operator *(Binary Multiplicand, int Multiplier) => Multiplicand * new Binary(BaseChange(Multiplier, 10, 2));

    public static Binary operator /(Binary Dividend /* m */, Binary Divisor /* n */)
    {
        Binary m = Dividend.Copy();
        Binary n = Divisor.Copy();

        /* Get the first set of digits of m where that set is the same length as n's digits */
        Binary quotient = new Binary(); //if N is 3 digits long, quotient starts with 000.

        Binary drop = new Binary();

        for (int i = 0; i < m.Length; i++)
        {
            drop += m[i];
            if (n <= drop)
            {
                quotient += '1';
            }
            else
            {
                quotient += '0';
            }
            drop = drop - n * MainClass.ValueOf(quotient[i]) /*0 or 1*/;
        }

        if (quotient.Body.IndexOf('1') != -1)   //If there's a one in it
        {
            while (quotient[0] != '1')
            {
                quotient.Body = quotient.Body.Substring(1);
            }
        }

        return(quotient);
    }

    /* End of Operators */
}
Example #7
0
 static public OrtogoonInt operator -(OrtogoonInt Minuend, Vektor2DInt Subtrahend)
 {
     return(Minuend.Versezt(-Subtrahend));
 }