]> www.ginac.de Git - ginac.git/blobdiff - ginac/add.cpp
Fixed bug in taking real and imaginary part.
[ginac.git] / ginac / add.cpp
index 9c314ee64dba61bbee6e05ebb950da7a2f6ebf9f..353b4a7744079ec1d73549454746a5a36eaf632f 100644 (file)
@@ -3,7 +3,7 @@
  *  Implementation of GiNaC's sums of expressions. */
 
 /*
- *  GiNaC Copyright (C) 1999-2006 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2007 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
@@ -429,11 +429,14 @@ ex add::real_part() const
        epvector v;
        v.reserve(seq.size());
        for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
-               if ((i->coeff).info(info_flags::real))
-                       v.push_back(expair((i->rest).real_part(), i->coeff));
-               else {
+               if ((i->coeff).info(info_flags::real)) {
+                       ex rp = (i->rest).real_part();
+                       if (!rp.is_zero())
+                               v.push_back(expair(rp, i->coeff));
+               } else {
                        ex rp=recombine_pair_to_ex(*i).real_part();
-                       v.push_back(split_ex_to_pair(rp));
+                       if (!rp.is_zero())
+                               v.push_back(split_ex_to_pair(rp));
                }
        return (new add(v, overall_coeff.real_part()))
                -> setflag(status_flags::dynallocated);
@@ -444,11 +447,14 @@ ex add::imag_part() const
        epvector v;
        v.reserve(seq.size());
        for (epvector::const_iterator i=seq.begin(); i!=seq.end(); ++i)
-               if ((i->coeff).info(info_flags::real))
-                       v.push_back(expair((i->rest).imag_part(), i->coeff));
-               else {
+               if ((i->coeff).info(info_flags::real)) {
+                       ex ip = (i->rest).imag_part();
+                       if (!ip.is_zero())
+                               v.push_back(expair(ip, i->coeff));
+               } else {
                        ex ip=recombine_pair_to_ex(*i).imag_part();
-                       v.push_back(split_ex_to_pair(ip));
+                       if (!ip.is_zero())
+                               v.push_back(split_ex_to_pair(ip));
                }
        return (new add(v, overall_coeff.imag_part()))
                -> setflag(status_flags::dynallocated);
@@ -503,12 +509,14 @@ tinfo_t add::return_type_tinfo() const
                return seq.begin()->rest.return_type_tinfo();
 }
 
-ex add::thisexpairseq(const epvector & v, const ex & oc) const
+// Note: do_index_renaming is ignored because it makes no sense for an add.
+ex add::thisexpairseq(const epvector & v, const ex & oc, bool do_index_renaming) const
 {
        return (new add(v,oc))->setflag(status_flags::dynallocated);
 }
 
-ex add::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc) const
+// Note: do_index_renaming is ignored because it makes no sense for an add.
+ex add::thisexpairseq(std::auto_ptr<epvector> vp, const ex & oc, bool do_index_renaming) const
 {
        return (new add(vp,oc))->setflag(status_flags::dynallocated);
 }