Beispiel #1
0
        public static RootSum Add(RootTerm x, RootTerm y)
        {
            if (x.IsZero)
            {
                return(new RootSum(y, RootTerm.Zero));
            }

            if (y.IsZero)
            {
                return(new RootSum(x, RootTerm.Zero));
            }

            if (x.X == y.X)
            {
                return(new RootSum((x.C + y.C) * RootTerm.Sqrt(x.X), RootTerm.Zero));
            }

            if (x.IsReal && y.IsReal)
            {
                if (x.X < y.X)
                {
                    return(new RootSum(x, y));
                }

                return(new RootSum(y, x));
            }

            if (x.IsReal)
            {
                return(new RootSum(x, y));
            }

            if (y.IsReal)
            {
                return(new RootSum(y, x));
            }

            if (x.X > y.X)
            {
                return(new RootSum(x, y));
            }

            return(new RootSum(y, x));
        }