[Numpy-svn] r6207 - trunk/numpy/core/src

numpy-svn@scip... numpy-svn@scip...
Sat Dec 27 07:48:56 CST 2008


Author: cdavid
Date: 2008-12-27 07:48:52 -0600 (Sat, 27 Dec 2008)
New Revision: 6207

Modified:
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Start working on formatting failure on 2.6: copy how python does complex formatting.

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2008-12-27 12:18:47 UTC (rev 6206)
+++ trunk/numpy/core/src/scalartypes.inc.src	2008-12-27 13:48:52 UTC (rev 6207)
@@ -610,6 +610,8 @@
  */
 
 #define FMT "%.*" NPY_@NAME@_FMT
+#define FMTR "%%.%i" NPY_@NAME@_FMT
+#define FMTI "%%+.%i" NPY_@NAME@_FMT
 #define CFMT1 "%.*" NPY_@NAME@_FMT "j"
 #define CFMT2 "(%.*" NPY_@NAME@_FMT "%+.*" NPY_@NAME@_FMT "j)"
 
@@ -634,11 +636,17 @@
 static void
 format_c@name@(char *buf, size_t buflen, c@name@ val, unsigned int prec)
 {
+    char format[32];
     if (val.real == 0.0) {
         PyOS_snprintf(buf, buflen, CFMT1, prec, val.imag);
     }
     else {
-        PyOS_snprintf(buf, buflen, CFMT2, prec, val.real, prec, val.imag);
+	char re[64], im[64];
+        PyOS_snprintf(format, sizeof(format), FMTR, prec);
+        PyOS_ascii_formatd(re, sizeof(re), format, val.real);
+        PyOS_snprintf(format, sizeof(format), FMTI, prec);
+        PyOS_ascii_formatd(im, sizeof(im), format, val.imag);
+        PyOS_snprintf(buf, buflen, "(%s%sj)", re, im);
     }
 }
 



More information about the Numpy-svn mailing list