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

eric.smith python-checkins at python.org
Sun Apr 5 00:39:35 CEST 2009


Author: eric.smith
Date: Sun Apr  5 00:39:34 2009
New Revision: 71199

Log:
Removed PREC_STR and hard-coded 's' precision inside PyOS_double_to_string().

Modified:
   python/branches/py3k-short-float-repr/Objects/complexobject.c
   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/complexobject.c
==============================================================================
--- python/branches/py3k-short-float-repr/Objects/complexobject.c	(original)
+++ python/branches/py3k-short-float-repr/Objects/complexobject.c	Sun Apr  5 00:39:34 2009
@@ -14,15 +14,6 @@
 
 #ifndef WITHOUT_COMPLEX
 
-/* Precision used by str().
-
-   The str() precision is chosen so that in most cases, the rounding noise
-   created by various operations is suppressed, while giving plenty of
-   precision for practical use.
-*/
-
-#define PREC_STR	12
-
 /* elementary operations on complex numbers */
 
 static Py_complex c_1 = {1., 0.};
@@ -339,7 +330,7 @@
 
 
 static PyObject *
-complex_format(PyComplexObject *v, char format_code, int precision)
+complex_format(PyComplexObject *v, char format_code)
 {
     PyObject *result = NULL;
     Py_ssize_t len;
@@ -368,8 +359,7 @@
                 im = "-inf*";
         }
         else {
-            pim = PyOS_double_to_string(v->cval.imag, format_code,
-                                        precision, 0);
+            pim = PyOS_double_to_string(v->cval.imag, format_code, 0, 0);
             if (!pim) {
                 PyErr_NoMemory();
                 goto done;
@@ -388,8 +378,7 @@
                 re = "-inf";
         }
         else {
-            pre = PyOS_double_to_string(v->cval.real, format_code,
-                                        precision, 0);
+            pre = PyOS_double_to_string(v->cval.real, format_code, 0, 0);
             if (!pre) {
                 PyErr_NoMemory();
                 goto done;
@@ -408,7 +397,7 @@
         }
         else {
             pim = PyOS_double_to_string(v->cval.imag, format_code,
-                                        precision, Py_DTSF_SIGN);
+                                        0, Py_DTSF_SIGN);
             if (!pim) {
                 PyErr_NoMemory();
                 goto done;
@@ -438,13 +427,13 @@
 static PyObject *
 complex_repr(PyComplexObject *v)
 {
-    return complex_format(v, 'r', 0);
+    return complex_format(v, 'r');
 }
 
 static PyObject *
 complex_str(PyComplexObject *v)
 {
-    return complex_format(v, 's', PREC_STR);
+    return complex_format(v, 's');
 }
 
 static long

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	Sun Apr  5 00:39:34 2009
@@ -354,23 +354,12 @@
 	return 0;
 }
 
-/* Precision used by str().
-
-   The str() precision is chosen so that in most cases, the rounding noise
-   created by various operations is suppressed, while giving plenty of
-   precision for practical use.
-
-*/
-
-#define PREC_STR	12
-
 static PyObject *
-float_str_or_repr(PyFloatObject *v, char format_code, int precision)
+float_str_or_repr(PyFloatObject *v, char format_code)
 {
     PyObject *result;
     char *buf = PyOS_double_to_string(PyFloat_AS_DOUBLE(v),
-                                      format_code, precision,
-                                      Py_DTSF_ADD_DOT_0);
+                                      format_code, 0, Py_DTSF_ADD_DOT_0);
     if (!buf)
         return PyErr_NoMemory();
     result = PyUnicode_FromString(buf);
@@ -381,13 +370,13 @@
 static PyObject *
 float_repr(PyFloatObject *v)
 {
-    return float_str_or_repr(v, 'r', 0);
+    return float_str_or_repr(v, 'r');
 }
 
 static PyObject *
 float_str(PyFloatObject *v)
 {
-    return float_str_or_repr(v, 's', PREC_STR);
+    return float_str_or_repr(v, 's');
 }
 
 /* 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	Sun Apr  5 00:39:34 2009
@@ -746,9 +746,20 @@
 	case 'r':
 		/* "repr" pseudo-mode */
 		mode = 0;
+		/* Supplied precision is unused, must be 0. */
+		if (precision != 0) {
+			PyErr_BadInternalCall();
+			return NULL;
+		}
 		break;
 	case 's':
 		mode = 2;
+		/* Supplied precision is unused, must be 0. */
+		if (precision != 0) {
+			PyErr_BadInternalCall();
+			return NULL;
+		}
+		precision = 12;
 		break;
 	}
 


More information about the Python-checkins mailing list