Commits

Georg Brandl  committed f4c2c61

backport patch [ 1118729 ] Error in representation of complex numbers(again)

  • Participants
  • Parent commits 5a6c483
  • Branches 2.4

Comments (0)

Files changed (1)

File Objects/complexobject.c

 		strncat(buf, "j", bufsz);
 	} else {
 		char re[64], im[64];
-		char *fmt;
+		/* Format imaginary part with sign, real part without */
 		PyOS_snprintf(format, 32, "%%.%ig", precision);
 		PyOS_ascii_formatd(re, 64, format, v->cval.real);
+		PyOS_snprintf(format, 32, "%%+.%ig", precision);
 		PyOS_ascii_formatd(im, 64, format, v->cval.imag);
-		if (v->cval.imag < 0.)
-			fmt = "(%s%sj)";
-		else
-			fmt = "(%s+%sj)";
-		PyOS_snprintf(buf, bufsz, fmt, re, im);
+		PyOS_snprintf(buf, bufsz, "(%s%sj)", re, im);
 	}
 }