Beispiel #1
0
        public override string ToString()
        {
            string res;

            if (Prefix.CompareTo(Constant.MinusOne))
            {
                res = "-" + Identifier.ToString();
            }
            else if (!Prefix.CompareTo(Constant.One))
            {
                res = Prefix.ToString() + Identifier.ToString();
            }
            else
            {
                res = Identifier.ToString();
            }

            if (!Exponent.CompareTo(Constant.One))
            {
                res += "^" + Exponent.ToString();
            }

            return(res);
        }
Beispiel #2
0
        public override bool CompareTo(Expression other)
        {
            var otherReduced = other.Reduce();

            if (otherReduced is Variable)
            {
                if (Identifier == (otherReduced as Variable).Identifier && Prefix.CompareTo((otherReduced as Variable).Prefix) && Exponent.CompareTo((otherReduced as Variable).Exponent))
                {
                    return(true);
                }

                if (IsDefined && (otherReduced as Variable).IsDefined)
                {
                    return(Value.CompareTo(otherReduced.Value));
                }
            }

            if (IsDefined)
            {
                return(otherReduced.CompareTo(Value));
            }

            return(false);
        }