+
+ const std::string par_open = is_a<print_latex>(c) ? "{(" : "(";
+ const std::string par_close = is_a<print_latex>(c) ? ")}" : ")";
+ const std::string imag_sym = is_a<print_latex>(c) ? "i" : "I";
+ const std::string mul_sym = is_a<print_latex>(c) ? " " : "*";
+ 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 (is_a<print_python_repr>(c))
+ c.s << class_name() << "('";
+ if (cln::zerop(i)) {
+ // case 1, real: x or -x
+ if ((precedence() <= level) && (!this->is_nonneg_integer())) {
+ c.s << par_open;
+ print_real_number(c, r);
+ c.s << par_close;
+ } else {
+ print_real_number(c, r);
+ }
+ } else {
+ if (cln::zerop(r)) {
+ // case 2, imaginary: y*I or -y*I
+ 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;
+ }
+ 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
+ if (precedence() <= level)
+ c.s << par_open;
+ print_real_number(c, r);
+ if (i < 0) {
+ if (i == -1) {
+ c.s << "-"+imag_sym;
+ } else {
+ print_real_number(c, i);
+ c.s << mul_sym+imag_sym;
+ }
+ } else {
+ if (i == 1) {
+ c.s << "+"+imag_sym;
+ } else {
+ c.s << "+";
+ print_real_number(c, i);
+ c.s << mul_sym+imag_sym;
+ }
+ }
+ if (precedence() <= level)
+ c.s << par_close;
+ }
+ }
+ if (is_a<print_python_repr>(c))
+ c.s << "')";