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

numpy-svn@scip... numpy-svn@scip...
Thu Apr 10 20:54:21 CDT 2008


Author: charris
Date: 2008-04-10 20:54:18 -0500 (Thu, 10 Apr 2008)
New Revision: 5013

Modified:
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Add functions for str instead of defining them to the same as repr. Reduce repr
precision of longdouble to 20 and set str precision of longdouble to the same as
double. This is a first cut at looking through the formatting used to print
numbers. 

The precisions are now

#define FLOATPREC_REPR 8
#define FLOATPREC_STR 6
#define DOUBLEPREC_REPR 17
#define DOUBLEPREC_STR 12
#if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE
#define LONGDOUBLEPREC_REPR DOUBLEPREC_REPR
#define LONGDOUBLEPREC_STR DOUBLEPREC_STR
#else /* More than probably needed on Intel FP */
#define LONGDOUBLEPREC_REPR 20
#define LONGDOUBLEPREC_STR 12
#endif

This line, and those below, will be ignored--

M    numpy/core/src/scalartypes.inc.src


Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2008-04-10 23:58:42 UTC (rev 5012)
+++ trunk/numpy/core/src/scalartypes.inc.src	2008-04-11 01:54:18 UTC (rev 5013)
@@ -610,16 +610,49 @@
 
 /* These values are finfo.precision + 2 */
 #define FLOATPREC_REPR 8
+#define FLOATPREC_STR 6
 #define DOUBLEPREC_REPR 17
-
+#define DOUBLEPREC_STR 12
 #if SIZEOF_LONGDOUBLE == SIZEOF_DOUBLE
 #define LONGDOUBLEPREC_REPR DOUBLEPREC_REPR
-#define LONGDOUBLEPREC_STR DOUBLEPREC_REPR
+#define LONGDOUBLEPREC_STR DOUBLEPREC_STR
 #else /* More than probably needed on Intel FP */
-#define LONGDOUBLEPREC_REPR 22
-#define LONGDOUBLEPREC_STR 22
+#define LONGDOUBLEPREC_REPR 20
+#define LONGDOUBLEPREC_STR 12
 #endif
 
+/* floattype_str */
+/**begin repeat
+
+#name=float, double, longdouble#
+#Name=Float, Double, LongDouble#
+#NAME=FLOAT, DOUBLE, LONGDOUBLE#
+*/
+static PyObject *
+@name@type_str(PyObject *self)
+{
+        static char buf[100];
+        format_@name@(buf, sizeof(buf),
+                          ((Py@Name@ScalarObject *)self)->obval, @NAME@PREC_STR);
+        return PyString_FromString(buf);
+}
+
+static PyObject *
+c@name@type_str(PyObject *self)
+{
+        static char buf1[100];
+        static char buf2[100];
+        static char buf3[202];
+        c@name@ x;
+        x = ((PyC@Name@ScalarObject *)self)->obval;
+        format_@name@(buf1, sizeof(buf1), x.real, @NAME@PREC_STR);
+        format_@name@(buf2, sizeof(buf2), x.imag, @NAME@PREC_STR);
+
+        snprintf(buf3, sizeof(buf3), "(%s+%sj)", buf1, buf2);
+        return PyString_FromString(buf3);
+}
+/**end repeat**/
+
 /* floattype_repr */
 /**begin repeat
 
@@ -652,14 +685,7 @@
 }
 /**end repeat**/
 
-/**begin repeat
 
-#name=float, double, longdouble#
-*/
-#define @name@type_str @name@type_repr
-#define c@name@type_str c@name@type_repr
-/**end repeat**/
-
 /** Could improve this with a PyLong_FromLongDouble(longdouble ldval)
     but this would need some more work...
 **/



More information about the Numpy-svn mailing list