]> granicus.if.org Git - python/commitdiff
patch [ 1118729 ] Error in representation of complex numbers(again)
authorGeorg Brandl <georg@python.org>
Fri, 16 Sep 2005 06:42:26 +0000 (06:42 +0000)
committerGeorg Brandl <georg@python.org>
Fri, 16 Sep 2005 06:42:26 +0000 (06:42 +0000)
Objects/complexobject.c

index 81bcca87c65e163e462f160c5c0214a35f73d8d0..138ba8042aad3866027ba4f675e841006067fce9 100644 (file)
@@ -279,15 +279,12 @@ complex_to_buf(char *buf, int bufsz, PyComplexObject *v, int precision)
                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);
        }
 }