]> www.ginac.de Git - ginac.git/blobdiff - ginac/numeric.cpp
* numeric::print(): Treat imaginary numbers correctly.
[ginac.git] / ginac / numeric.cpp
index f1be0bcbe960d0df61609a9809e70b931c01efff..55d5d556526e3038f47684e53a665527791cb9e8 100644 (file)
@@ -7,7 +7,7 @@
  *  of special functions or implement the interface to the bignum package. */
 
 /*
- *  GiNaC Copyright (C) 1999-2001 Johannes Gutenberg University Mainz, Germany
+ *  GiNaC Copyright (C) 1999-2002 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
@@ -403,25 +403,19 @@ void numeric::print(const print_context & c, unsigned level) const
                } else {
                        if (cln::zerop(r)) {
                                // case 2, imaginary:  y*I  or  -y*I
-                               if ((precedence() <= level) && (i < 0)) {
-                                       if (i == -1) {
-                                               c.s << par_open+imag_sym+par_close;
-                                       } else {
+                               if (i==1)
+                                       c.s << imag_sym;
+                               else {
+                                       if (precedence()<=level)
                                                c.s << par_open;
+                                       if (i == -1)
+                                               c.s << "-" << imag_sym;
+                                       else {
                                                print_real_number(c, i);
-                                               c.s << mul_sym+imag_sym+par_close;
-                                       }
-                               } else {
-                                       if (i == 1) {
-                                               c.s << imag_sym;
-                                       } else {
-                                               if (i == -1) {
-                                                       c.s << "-" << imag_sym;
-                                               } else {
-                                                       print_real_number(c, i);
-                                                       c.s << mul_sym+imag_sym;
-                                               }
+                                               c.s << mul_sym+imag_sym;
                                        }
+                                       if (precedence()<=level)
+                                               c.s << par_close;
                                }
                        } else {
                                // case 3, complex:  x+y*I  or  x-y*I  or  -x+y*I  or  -x-y*I
@@ -498,6 +492,21 @@ bool numeric::info(unsigned inf) const
        return false;
 }
 
+int numeric::degree(const ex & s) const
+{
+       return 0;
+}
+
+int numeric::ldegree(const ex & s) const
+{
+       return 0;
+}
+
+ex numeric::coeff(const ex & s, int n) const
+{
+       return n==0 ? *this : _ex0;
+}
+
 /** Disassemble real part and imaginary part to scan for the occurrence of a
  *  single number.  Also handles the imaginary unit.  It ignores the sign on
  *  both this and the argument, which may lead to what might appear as funny