]> www.ginac.de Git - ginac.git/blobdiff - ginac/numeric.cpp
* color.cpp: remove duplicated default args.
[ginac.git] / ginac / numeric.cpp
index 1308c9e1cf736ddda40e9eb9247aee6bf1a7a95f..ef4e3e929ce5732f854bfae80d3f72f9f55e2b34 100644 (file)
@@ -410,15 +410,18 @@ void numeric::print(const print_context & c, unsigned level) const
                c.s.flags(oldflags);
 
        } else {
-
-               cln::cl_R r = cln::realpart(cln::the<cln::cl_N>(value));
-               cln::cl_R i = cln::imagpart(cln::the<cln::cl_N>(value));
+               const std::string par_open  = is_of_type(c, print_latex) ? "{(" : "(";
+               const std::string par_close = is_of_type(c, print_latex) ? ")}" : ")";
+               const std::string imag_sym  = is_of_type(c, print_latex) ? "i" : "I";
+               const std::string mul_sym   = is_of_type(c, print_latex) ? " " : "*";
+               const cln::cl_R r = cln::realpart(cln::the<cln::cl_N>(value));
+               const cln::cl_R i = cln::imagpart(cln::the<cln::cl_N>(value));
                if (cln::zerop(i)) {
                        // case 1, real:  x  or  -x
                        if ((precedence <= level) && (!this->is_nonneg_integer())) {
-                               c.s << "(";
+                               c.s << par_open;
                                print_real_number(c.s, r);
-                               c.s << ")";
+                               c.s << par_close;
                        } else {
                                print_real_number(c.s, r);
                        }
@@ -427,47 +430,47 @@ void numeric::print(const print_context & c, unsigned level) const
                                // case 2, imaginary:  y*I  or  -y*I
                                if ((precedence <= level) && (i < 0)) {
                                        if (i == -1) {
-                                               c.s << "(-I)";
+                                               c.s << par_open+imag_sym+par_close;
                                        } else {
-                                               c.s << "(";
+                                               c.s << par_open;
                                                print_real_number(c.s, i);
-                                               c.s << "*I)";
+                                               c.s << mul_sym+imag_sym+par_close;
                                        }
                                } else {
                                        if (i == 1) {
-                                               c.s << "I";
+                                               c.s << imag_sym;
                                        } else {
                                                if (i == -1) {
-                                                       c.s << "-I";
+                                                       c.s << "-" << imag_sym;
                                                } else {
                                                        print_real_number(c.s, i);
-                                                       c.s << "*I";
+                                                       c.s << mul_sym+imag_sym;
                                                }
                                        }
                                }
                        } else {
                                // case 3, complex:  x+y*I  or  x-y*I  or  -x+y*I  or  -x-y*I
                                if (precedence <= level)
-                                       c.s << "(";
+                                       c.s << par_open;
                                print_real_number(c.s, r);
                                if (i < 0) {
                                        if (i == -1) {
-                                               c.s << "-I";
+                                               c.s << "-"+imag_sym;
                                        } else {
                                                print_real_number(c.s, i);
-                                               c.s << "*I";
+                                               c.s << mul_sym+imag_sym;
                                        }
                                } else {
                                        if (i == 1) {
-                                               c.s << "+I";
+                                               c.s << "+"+imag_sym;
                                        } else {
                                                c.s << "+";
                                                print_real_number(c.s, i);
-                                               c.s << "*I";
+                                               c.s << mul_sym+imag_sym;
                                        }
                                }
                                if (precedence <= level)
-                                       c.s << ")";
+                                       c.s << par_close;
                        }
                }
        }
@@ -935,13 +938,13 @@ bool numeric::is_real(void) const
 
 bool numeric::operator==(const numeric &other) const
 {
-       return equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
+       return cln::equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
 }
 
 
 bool numeric::operator!=(const numeric &other) const
 {
-       return !equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
+       return !cln::equal(cln::the<cln::cl_N>(value), cln::the<cln::cl_N>(other.value));
 }
 
 
@@ -1111,7 +1114,7 @@ const numeric numeric::denom(void) const
        if (this->is_integer())
                return _num1();
        
-       if (instanceof(value, cln::cl_RA_ring))
+       if (cln::instanceof(value, cln::cl_RA_ring))
                return numeric(cln::denominator(cln::the<cln::cl_RA>(value)));
        
        if (!this->is_real()) {  // complex case, handle Q(i):
@@ -1747,8 +1750,8 @@ const numeric irem(const numeric &a, const numeric &b, numeric &q)
 const numeric iquo(const numeric &a, const numeric &b)
 {
        if (a.is_integer() && b.is_integer())
-               return truncate1(cln::the<cln::cl_I>(a.to_cl_N()),
-                            cln::the<cln::cl_I>(b.to_cl_N()));
+               return cln::truncate1(cln::the<cln::cl_I>(a.to_cl_N()),
+                                 cln::the<cln::cl_I>(b.to_cl_N()));
        else
                return _num0();
 }