- 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;
+ 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;