- Banned exZERO(), exONE(), exMINUSHALF() and all this from the interface.
[ginac.git] / ginac / relational.cpp
index 76652e980198a65a483632ce07b5614d55f9ff42..614c1629c11382ab66db911d07a5c02bcc9a59a1 100644 (file)
 #include "relational.h"
 #include "numeric.h"
 #include "debugmsg.h"
+#include "utils.h"
 
+#ifndef NO_GINAC_NAMESPACE
 namespace GiNaC {
+#endif // ndef NO_GINAC_NAMESPACE
 
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
@@ -102,6 +105,111 @@ basic * relational::duplicate() const
     return new relational(*this);
 }
 
+void relational::print(ostream & os, unsigned upper_precedence) const
+{
+    debugmsg("relational print",LOGLEVEL_PRINT);
+    if (precedence<=upper_precedence) os << "(";
+    lh.print(os,precedence);
+    switch (o) {
+    case equal:
+        os << "==";
+        break;
+    case not_equal:
+        os << "!=";
+        break;
+    case less:
+        os << "<";
+        break;
+    case less_or_equal:
+        os << "<=";
+        break;
+    case greater:
+        os << ">";
+        break;
+    case greater_or_equal:
+        os << ">=";
+        break;
+    default:
+        os << "(INVALID RELATIONAL OPERATOR)";
+    }
+    rh.print(os,precedence);
+    if (precedence<=upper_precedence) os << ")";
+}
+
+void relational::printraw(ostream & os) const
+{
+    debugmsg("relational printraw",LOGLEVEL_PRINT);
+    os << "RELATIONAL(";
+    lh.printraw(os);
+    os << ",";
+    rh.printraw(os);
+    os << ",";
+    switch (o) {
+    case equal:
+        os << "==";
+        break;
+    case not_equal:
+        os << "!=";
+        break;
+    case less:
+        os << "<";
+        break;
+    case less_or_equal:
+        os << "<=";
+        break;
+    case greater:
+        os << ">";
+        break;
+    case greater_or_equal:
+        os << ">=";
+        break;
+    default:
+        os << "(INVALID RELATIONAL OPERATOR)";
+    }
+    os << ")";
+}
+
+void relational::printcsrc(ostream & os, unsigned type, unsigned upper_precedence) const
+{
+    debugmsg("relational print csrc", LOGLEVEL_PRINT);
+    if (precedence<=upper_precedence)
+        os << "(";
+
+    // Print left-hand expression
+    lh.bp->printcsrc(os, type, precedence);
+
+    // Print relational operator
+    switch (o) {
+        case equal:
+            os << "==";
+            break;
+        case not_equal:
+            os << "!=";
+            break;
+        case less:
+            os << "<";
+            break;
+        case less_or_equal:
+            os << "<=";
+            break;
+        case greater:
+            os << ">";
+            break;
+        case greater_or_equal:
+            os << ">=";
+            break;
+        default:
+            os << "(INVALID RELATIONAL OPERATOR)";
+            break;
+    }
+
+    // Print right-hand operator
+    rh.bp->printcsrc(os, type, precedence);
+
+    if (precedence <= upper_precedence)
+        os << ")";
+}
+
 bool relational::info(unsigned inf) const
 {
     switch (inf) {
@@ -223,7 +331,7 @@ relational::operator bool() const
     if (!is_ex_exactly_of_type(df,numeric)) {
         return o==not_equal ? true : false; // cannot decide on non-numerical results
     }
-    int cmpval=ex_to_numeric(df).compare(numZERO());
+    int cmpval=ex_to_numeric(df).compare(_num0());
     switch (o) {
     case equal:
         return cmpval==0;
@@ -264,4 +372,6 @@ unsigned relational::precedence=20;
 const relational some_relational;
 type_info const & typeid_relational=typeid(some_relational);
 
+#ifndef NO_GINAC_NAMESPACE
 } // namespace GiNaC
+#endif // ndef NO_GINAC_NAMESPACE