Exemplo n.º 1
0
        public static SPolynom operator +(SPolynom a, SPolynom b)
        {
            double[] temp = null;
            if (a.Degree >= b.Degree)
            {
                temp = new double[a.ReversedTerms.Length];
                a.ReversedTerms.CopyTo(temp, 0);
                for (int i = 0; i < b.ReversedTerms.Length; i++)
                {
                    temp[i] += b.ReversedTerms[i];
                }
            }
            else if (a.Degree < b.Degree)
            {
                temp = new double[b.ReversedTerms.Length];
                b.ReversedTerms.CopyTo(temp, 0);
                for (int i = 0; i < a.ReversedTerms.Length; i++)
                {
                    temp[i] += a.ReversedTerms[i];
                }
            }

            SPolynom check = new SPolynom(temp.Reverse().ToArray());

            return(check.Terms.All(x => x == 0) ? new SPolynom(new double[] { 0 }) : check);
        }
Exemplo n.º 2
0
        public static SPolynom operator /(SPolynom a, SPolynom b)
        {
            double[] temp = null;
            if (a.Degree >= b.Degree)
            {
                temp = new double[a.ReversedTerms.Length];
                a.ReversedTerms.CopyTo(temp, 0);
                for (int i = 0; i < b.ReversedTerms.Length; i++)
                {
                    temp[i] /= b.ReversedTerms[i];
                    if (double.IsInfinity(temp[i]) || double.IsNaN(temp[i]))
                    {
                        throw new DivideByZeroException();
                    }
                }
            }
            else if (a.Degree < b.Degree)
            {
                temp = new double[b.ReversedTerms.Length];
                b.ReversedTerms.CopyTo(temp, 0);
                for (int i = 0; i < a.ReversedTerms.Length; i++)
                {
                    temp[i] /= a.ReversedTerms[i];
                    if (double.IsInfinity(temp[i]) || double.IsNaN(temp[i]))
                    {
                        throw new DivideByZeroException();
                    }
                }
            }

            SPolynom check = new SPolynom(temp.Reverse().ToArray());

            return(check.Terms.All(x => x == 0) ? new SPolynom(new double[] { 0 }) : check);
        }
Exemplo n.º 3
0
        public override bool Equals(object obj)
        {
            if ((obj == null) || !this.GetType().Equals(obj.GetType()))
            {
                return(false);
            }

            SPolynom temp = (SPolynom)obj;

            if (this.GetHashCode() == temp.GetHashCode())
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Exemplo n.º 4
0
        public static SPolynom operator -(SPolynom a, SPolynom b)
        {
            double[] temp = new double[b.Terms.Length];
            b.Terms.CopyTo(temp, 0);
            for (int i = 0; i < temp.Length; i++)
            {
                temp[i] *= -1;
            }

            SPolynom check = a + new SPolynom(temp);

            if (check.Terms.All(x => x == 0))
            {
                return(new SPolynom(new double[] { 0 }));
            }
            else
            {
                return(check);
            }
        }