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

numpy-svn@scip... numpy-svn@scip...
Sat Dec 27 08:59:52 CST 2008


Author: cdavid
Date: 2008-12-27 08:59:41 -0600 (Sat, 27 Dec 2008)
New Revision: 6210

Modified:
   trunk/numpy/core/src/scalartypes.inc.src
Log:
Finish formatting fixes for float scalar arrays.

Modified: trunk/numpy/core/src/scalartypes.inc.src
===================================================================
--- trunk/numpy/core/src/scalartypes.inc.src	2008-12-27 14:53:15 UTC (rev 6209)
+++ trunk/numpy/core/src/scalartypes.inc.src	2008-12-27 14:59:41 UTC (rev 6210)
@@ -615,6 +615,8 @@
 #define CFMT1 "%.*" NPY_@NAME@_FMT "j"
 #define CFMT2 "(%.*" NPY_@NAME@_FMT "%+.*" NPY_@NAME@_FMT "j)"
 
+/* Both format functions are shameless copies from python floatobject and
+ * complexobject files */
 static void
 format_@name@(char *buf, size_t buflen, @name@ val, unsigned int prec)
 {
@@ -622,7 +624,6 @@
     char format[32];
     register char* cp;
 
-    //cnt = PyOS_snprintf(buf, buflen, FMT, prec, val);
     PyOS_snprintf(format, sizeof(format), "%%.%i" NPY_@NAME@_FMT, prec);
     PyOS_ascii_formatd(buf, buflen, format, val);
     cp = buf;
@@ -644,6 +645,29 @@
 	cp += 3;
 	return ;
     }
+    /* Checking the next three chars should be more than enough to
+     * detect inf or nan, even on Windows. We check for inf or nan
+     * at last because they are rare cases.
+     */
+    for (i=0; *cp != '\0' && i<3; cp++, i++) {
+	if (isdigit(Py_CHARMASK(*cp)) || *cp == '.') {
+	    continue;
+	}
+	/* found something that is neither a digit nor point
+	* it might be a NaN or INF
+	*/
+	if (isnan(val)) {
+	    strcpy(buf, "nan");
+        }
+	else if (isinf(val)) {
+           cp = buf;
+           if (*cp == '-') {
+                cp++;
+           }
+           strcpy(cp, "inf");
+        }
+        break;
+    }
 }
 
 static void



More information about the Numpy-svn mailing list