[Numpy-svn] r6225 - in branches/fix_float_format/numpy/core: . src

numpy-svn@scip... numpy-svn@scip...
Sun Dec 28 21:20:42 CST 2008


Author: cdavid
Date: 2008-12-28 21:20:38 -0600 (Sun, 28 Dec 2008)
New Revision: 6225

Modified:
   branches/fix_float_format/numpy/core/setup.py
   branches/fix_float_format/numpy/core/src/scalartypes.inc.src
Log:
Use custom formatting functions.

Modified: branches/fix_float_format/numpy/core/setup.py
===================================================================
--- branches/fix_float_format/numpy/core/setup.py	2008-12-29 03:10:10 UTC (rev 6224)
+++ branches/fix_float_format/numpy/core/setup.py	2008-12-29 03:20:38 UTC (rev 6225)
@@ -330,6 +330,7 @@
     deps = [join('src','arrayobject.c'),
             join('src','arraymethods.c'),
             join('src','scalartypes.inc.src'),
+            join('src','npy_format.c'),
             join('src','arraytypes.inc.src'),
             join('src','_signbit.c'),
             join('src','ucsnarrow.c'),

Modified: branches/fix_float_format/numpy/core/src/scalartypes.inc.src
===================================================================
--- branches/fix_float_format/numpy/core/src/scalartypes.inc.src	2008-12-29 03:10:10 UTC (rev 6224)
+++ branches/fix_float_format/numpy/core/src/scalartypes.inc.src	2008-12-29 03:20:38 UTC (rev 6225)
@@ -5,6 +5,8 @@
 #endif
 #include "numpy/arrayscalars.h"
 
+#include "npy_format.c"
+
 static PyBoolScalarObject _PyArrayScalar_BoolValues[2] = {
     {PyObject_HEAD_INIT(&PyBoolArrType_Type) 0},
     {PyObject_HEAD_INIT(&PyBoolArrType_Type) 1},
@@ -607,15 +609,25 @@
 /**begin repeat
  * #name=float, double, longdouble#
  * #NAME=FLOAT, DOUBLE, LONGDOUBLE#
+ * #type=f, d, l#
  */
 
 #define FMT "%.*" NPY_@NAME@_FMT
 #define CFMT1 "%.*" NPY_@NAME@_FMT "j"
 #define CFMT2 "(%.*" NPY_@NAME@_FMT "%+.*" NPY_@NAME@_FMT "j)"
+#define _FMT1 "%%.%i" NPY_@NAME@_FMT
+#define _FMT2 "%%+.%i" NPY_@NAME@_FMT
 
 static void
 format_@name@(char *buf, size_t buflen, @name@ val, unsigned int prec)
 {
+    /* XXX: Find a correct size here for format string */
+    /* XXX: check for inf and nan */
+    char format[64];
+    PyOS_snprintf(format, sizeof(format), _FMT1, prec);
+    NumPyOS_ascii_format@type@(buf, buflen, format, val);
+
+#if 0
     int cnt, i;
 
     cnt = PyOS_snprintf(buf, buflen, FMT, prec, val);
@@ -629,22 +641,36 @@
     if (i == cnt && buflen >= cnt + 3) {
         strcpy(&buf[cnt],".0");
     }
+#endif
 }
 
 static void
 format_c@name@(char *buf, size_t buflen, c@name@ val, unsigned int prec)
 {
+    /* XXX: Find a correct size here for format string */
+    /* XXX: check for inf and nan */
+    char format[64];
     if (val.real == 0.0) {
-        PyOS_snprintf(buf, buflen, CFMT1, prec, val.imag);
+        PyOS_snprintf(format, sizeof(format), _FMT1, prec);
+        NumPyOS_ascii_format@type@(buf, buflen-1, format, val.imag);
+	strncat(buf, "j", 1);
     }
     else {
-        PyOS_snprintf(buf, buflen, CFMT2, prec, val.real, prec, val.imag);
+	char re[64], im[64];
+	PyOS_snprintf(format, sizeof(format), _FMT1, prec);
+        NumPyOS_ascii_format@type@(re, sizeof(re), format, val.real);
+
+	PyOS_snprintf(format, sizeof(format), _FMT2, prec);
+        NumPyOS_ascii_format@type@(im, sizeof(im), format, val.imag);
+	PyOS_snprintf(buf, buflen, "(%s%sj)", re, im);
     }
 }
 
 #undef FMT
 #undef CFMT1
 #undef CFMT2
+#undef _FMT1
+#undef _FMT2
 
 /**end repeat**/
 



More information about the Numpy-svn mailing list