[Python-checkins] r71166 - in python/branches/py3k-short-float-repr: Objects/floatobject.c Python/pystrtod.c

mark.dickinson python-checkins at python.org
Sat Apr 4 18:17:21 CEST 2009


Author: mark.dickinson
Date: Sat Apr  4 18:17:21 2009
New Revision: 71166

Log:
Add 's' format code for str formatting.


Modified:
   python/branches/py3k-short-float-repr/Objects/floatobject.c
   python/branches/py3k-short-float-repr/Python/pystrtod.c

Modified: python/branches/py3k-short-float-repr/Objects/floatobject.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/floatobject.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/floatobject.c	Sat Apr  4 18:17:21 2009
@@ -387,7 +387,7 @@
 static PyObject *
 float_str(PyFloatObject *v)
 {
-    return float_str_or_repr(v, 'g', PREC_STR);
+    return float_str_or_repr(v, 's', PREC_STR);
 }
 
 /* Comparison is pretty much a nightmare.  When comparing float to float,

Modified: python/branches/py3k-short-float-repr/Python/pystrtod.c
==============================================================================
--- python/branches/py3k-short-float-repr/Python/pystrtod.c	(original)
+++ python/branches/py3k-short-float-repr/Python/pystrtod.c	Sat Apr  4 18:17:21 2009
@@ -617,6 +617,14 @@
 			use_exp = 1;
 		trailing_zeros = 0;
 		break;
+	case 's':
+		/* str: use exponent for values >= 1e11 or < 1e-4 */
+		if (-4 < decpt && decpt < precision)
+			use_exp = 0;
+		else
+			use_exp = 1;
+		trailing_zeros = 0;
+		break;
 	}
 
 	/* Always add a negative sign, and a plus sign if always_add_sign. */
@@ -710,6 +718,7 @@
 	case 'f':          /* fixed */
 	case 'g':          /* general */
 	case 'r':          /* repr format */
+	case 's':          /* str format */
 		break;
 	case 'E':
 		lc_format_code = 'e';
@@ -747,6 +756,9 @@
 		/* "repr" pseudo-mode */
 		mode = 0;
 		break;
+	case 's':
+		mode = 2;
+		break;
 	}
 
 	if (!buf)


More information about the Python-checkins mailing list