Exemple #1
0
        public static _Polynom operator -(_Polynom data1, _Polynom data2)
        {
            if (!ValidateForOperation(data1, data2))
            {
                throw new ArgumentNullException();
            }

            _Polynom result = new _Polynom(data1);

            foreach (var item in data2.listElements)
            {
                if (result.listElements[item.Key] != null)
                {
                    result.listElements[item.Key].coefficient -= item.Value.coefficient;

                    if (result.listElements[item.Key].coefficient == 0)
                    {
                        result.listElements.Remove(item.Key);
                    }
                }
                else
                {
                    result.Add(new Element(item.Value.coefficient * (-1), item.Value.power));
                }
            }

            return(result);
        }
Exemple #2
0
        public static _Polynom operator *(_Polynom data1, _Polynom data2)
        {
            if (!ValidateForOperation(data1, data2))
            {
                throw new ArgumentNullException();
            }

            _Polynom result = new _Polynom();

            foreach (var item1 in data1.listElements)
            {
                foreach (var item2 in data2.listElements)
                {
                    int    newPower = item1.Value.power + item2.Value.power;
                    double newCoef  = item1.Value.coefficient * item2.Value.coefficient;

                    result.Add(newCoef, newPower);
                }
            }

            return(result);
        }