- GINAC_ASSERT(is_exactly_of_type(other, relational));
- const relational & oth=static_cast<const relational &>(const_cast<basic &>(other));
-
- int cmpval;
-
- if (o == oth.o) {
- cmpval=lh.compare(oth.lh);
- if (cmpval==0) {
- return rh.compare(oth.rh);
- } else {
- return cmpval;
- }
- }
- if (o<oth.o) {
- return -1;
- } else {
- return 1;
- }
+ GINAC_ASSERT(is_exactly_a<relational>(other));
+ const relational &oth = static_cast<const relational &>(other);
+ if (o==oth.o && lh.is_equal(oth.lh) && rh.is_equal(oth.rh))
+ return 0;
+ switch (o) {
+ case equal:
+ case not_equal:
+ if (oth.o!=o)
+ return (o < oth.o) ? -1 : 1;
+ break;
+ case less:
+ if (oth.o!=greater)
+ return (o < oth.o) ? -1 : 1;
+ break;
+ case less_or_equal:
+ if (oth.o!=greater_or_equal)
+ return (o < oth.o) ? -1 : 1;
+ break;
+ case greater:
+ if (oth.o!=less)
+ return (o < oth.o) ? -1 : 1;
+ break;
+ case greater_or_equal:
+ if (oth.o!=less_or_equal)
+ return (o < oth.o) ? -1 : 1;
+ break;
+ }
+ const int lcmpval = lh.compare(oth.rh);
+ return (lcmpval!=0) ? lcmpval : rh.compare(oth.lh);
+}
+
+bool relational::match_same_type(const basic & other) const
+{
+ GINAC_ASSERT(is_exactly_a<relational>(other));
+ const relational &oth = static_cast<const relational &>(other);
+
+ return o == oth.o;
+}
+
+unsigned relational::return_type() const
+{
+ GINAC_ASSERT(lh.return_type()==rh.return_type());
+ return lh.return_type();