]> www.ginac.de Git - ginac.git/blobdiff - ginac/mul.cpp
- Use newer fig2dev which supports eps (old ones are broken now!)
[ginac.git] / ginac / mul.cpp
index 9bee46f2c86781193f04a26ccac08efef5de2228..b269836ab2c6e43e4dc726beb62dfc303c70a835 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's products of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2000 Johannes Gutenberg University Mainz, Germany
  *
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
@@ -26,6 +26,7 @@
 #include "mul.h"
 #include "add.h"
 #include "power.h"
+#include "archive.h"
 #include "debugmsg.h"
 #include "utils.h"
 
@@ -33,6 +34,8 @@
 namespace GiNaC {
 #endif // ndef NO_GINAC_NAMESPACE
 
+GINAC_IMPLEMENT_REGISTERED_CLASS(mul, expairseq)
+
 //////////
 // default constructor, destructor, copy constructor assignment operator and helpers
 //////////
@@ -71,12 +74,12 @@ mul const & mul::operator=(mul const & other)
 
 void mul::copy(mul const & other)
 {
-    expairseq::copy(other);
+    inherited::copy(other);
 }
 
 void mul::destroy(bool call_parent)
 {
-    if (call_parent) expairseq::destroy(call_parent);
+    if (call_parent) inherited::destroy(call_parent);
 }
 
 //////////
@@ -163,6 +166,28 @@ mul::mul(ex const & lh, ex const & mh, ex const & rh)
     GINAC_ASSERT(is_canonical());
 }
 
+//////////
+// archiving
+//////////
+
+/** Construct object from archive_node. */
+mul::mul(const archive_node &n, const lst &sym_lst) : inherited(n, sym_lst)
+{
+    debugmsg("mul constructor from archive_node", LOGLEVEL_CONSTRUCT);
+}
+
+/** Unarchive the object. */
+ex mul::unarchive(const archive_node &n, const lst &sym_lst)
+{
+    return (new mul(n, sym_lst))->setflag(status_flags::dynallocated);
+}
+
+/** Archive the object. */
+void mul::archive(archive_node &n) const
+{
+    inherited::archive(n);
+}
+
 //////////
 // functions overriding virtual functions from bases classes
 //////////
@@ -181,13 +206,21 @@ void mul::print(ostream & os, unsigned upper_precedence) const
     if (precedence<=upper_precedence) os << "(";
     bool first=true;
     // first print the overall numeric coefficient:
-    if (ex_to_numeric(overall_coeff).csgn()==-1) os << '-';
-    if (!overall_coeff.is_equal(_ex1()) &&
-        !overall_coeff.is_equal(_ex_1())) {
-        if (ex_to_numeric(overall_coeff).csgn()==-1)
-            (_num_1()*overall_coeff).print(os, precedence);
-        else
-            overall_coeff.print(os, precedence);
+    numeric coeff = ex_to_numeric(overall_coeff);
+    if (coeff.csgn()==-1) os << '-';
+    if (!coeff.is_equal(_num1()) &&
+        !coeff.is_equal(_num_1())) {
+        if (coeff.is_rational()) {
+            if (coeff.is_negative())
+                os << -coeff;
+            else
+                os << coeff;
+        } else {
+            if (coeff.csgn()==-1)
+                (-coeff).print(os, precedence);
+            else
+                coeff.print(os, precedence);
+        }
         os << '*';
     }
     // then proceed with the remaining factors:
@@ -277,7 +310,7 @@ bool mul::info(unsigned inf) const
         }
         return overall_coeff.info(inf);
     } else {
-        return expairseq::info(inf);
+        return inherited::info(inf);
     }
 }
 
@@ -431,12 +464,12 @@ ex mul::simplify_ncmul(exvector const & v) const
 
 int mul::compare_same_type(basic const & other) const
 {
-    return expairseq::compare_same_type(other);
+    return inherited::compare_same_type(other);
 }
 
 bool mul::is_equal_same_type(basic const & other) const
 {
-    return expairseq::is_equal_same_type(other);
+    return inherited::is_equal_same_type(other);
 }
 
 unsigned mul::return_type(void) const
@@ -620,7 +653,7 @@ ex mul::expand(unsigned options) const
             (ex_to_numeric((*cit).coeff).is_equal(_num1()))) {
             positions_of_adds[number_of_adds]=current_position;
             add const & expanded_addref=ex_to_add((*cit).rest);
-            int addref_nops=expanded_addref.nops();
+            unsigned addref_nops=expanded_addref.nops();
             number_of_add_operands[number_of_adds]=addref_nops;
             number_of_expanded_terms *= addref_nops;
             number_of_adds++;