[Python-3000-checkins] r64515 - in python/branches/py3k: Include/floatobject.h Lib/test/test_builtin.py Objects/abstract.c Objects/floatobject.c

raymond.hettinger python-3000-checkins at python.org
Wed Jun 25 00:28:56 CEST 2008


Author: raymond.hettinger
Date: Wed Jun 25 00:28:56 2008
New Revision: 64515

Log:
Revert 64451.

Modified:
   python/branches/py3k/Include/floatobject.h
   python/branches/py3k/Lib/test/test_builtin.py
   python/branches/py3k/Objects/abstract.c
   python/branches/py3k/Objects/floatobject.c

Modified: python/branches/py3k/Include/floatobject.h
==============================================================================
--- python/branches/py3k/Include/floatobject.h	(original)
+++ python/branches/py3k/Include/floatobject.h	Wed Jun 25 00:28:56 2008
@@ -111,8 +111,6 @@
 					       Py_UNICODE *format_spec,
 					       Py_ssize_t format_spec_len);
 
-PyAPI_FUNC(PyObject *) _float_to_base(PyObject *v, int base);
-
 #ifdef __cplusplus
 }
 #endif

Modified: python/branches/py3k/Lib/test/test_builtin.py
==============================================================================
--- python/branches/py3k/Lib/test/test_builtin.py	(original)
+++ python/branches/py3k/Lib/test/test_builtin.py	Wed Jun 25 00:28:56 2008
@@ -553,15 +553,6 @@
         self.assertEqual(hex(-16), '-0x10')
         self.assertEqual(hex(-16), '-0x10')
         self.assertRaises(TypeError, hex, {})
-        self.assertEqual(hex(3.125), '0x19 * 2.0 ** -3')
-        self.assertEqual(hex(0.0), '0x0 * 2.0 ** 0')
-        for sv in float('nan'), float('inf'), float('-inf'):
-            self.assertEqual(hex(sv), repr(sv))
-        for i in range(100):
-            x = random.expovariate(.05)
-            self.assertEqual(eval(hex(x)), x, (x, hex(x), eval(hex(x))))
-            self.assertEqual(eval(hex(-x)), -x)
-            self.assertEqual(hex(-x), ('-' + hex(x)))
 
     def test_id(self):
         id(None)
@@ -805,15 +796,6 @@
         self.assertEqual(oct(-100), '-0o144')
         self.assertEqual(oct(-100), '-0o144')
         self.assertRaises(TypeError, oct, ())
-        self.assertEqual(oct(3.125), '0o31 * 2.0 ** -3')
-        self.assertEqual(oct(0.0), '0o0 * 2.0 ** 0')
-        for sv in float('nan'), float('inf'), float('-inf'):
-            self.assertEqual(oct(sv), repr(sv))
-        for i in range(100):
-            x = random.expovariate(.05)
-            self.assertEqual(eval(oct(x)), x)
-            self.assertEqual(eval(oct(-x)), -x)
-            self.assertEqual(oct(-x), ('-' + oct(x)))
 
     def write_testfile(self):
         # NB the first 4 lines are also used to test input, below
@@ -1231,15 +1213,6 @@
         self.assertEqual(bin(2**65-1), '0b' + '1' * 65)
         self.assertEqual(bin(-(2**65)), '-0b1' + '0' * 65)
         self.assertEqual(bin(-(2**65-1)), '-0b' + '1' * 65)
-        self.assertEqual(bin(3.125), '0b11001 * 2.0 ** -3')
-        self.assertEqual(bin(0.0), '0b0 * 2.0 ** 0')
-        for sv in float('nan'), float('inf'), float('-inf'):
-            self.assertEqual(bin(sv), repr(sv))
-        for i in range(100):
-            x = random.expovariate(.05)
-            self.assertEqual(eval(bin(x)), x)
-            self.assertEqual(eval(bin(-x)), -x)
-            self.assertEqual(bin(-x), ('-' + bin(x)))
 
 class TestSorted(unittest.TestCase):
 

Modified: python/branches/py3k/Objects/abstract.c
==============================================================================
--- python/branches/py3k/Objects/abstract.c	(original)
+++ python/branches/py3k/Objects/abstract.c	Wed Jun 25 00:28:56 2008
@@ -1451,11 +1451,8 @@
 PyNumber_ToBase(PyObject *n, int base)
 {
 	PyObject *res = NULL;
-	PyObject *index;
+	PyObject *index = PyNumber_Index(n);
 
-	if (PyFloat_Check(n))
-		return _float_to_base(n, base);
-	index = PyNumber_Index(n);
 	if (!index)
 		return NULL;
 	if (PyLong_Check(index))

Modified: python/branches/py3k/Objects/floatobject.c
==============================================================================
--- python/branches/py3k/Objects/floatobject.c	(original)
+++ python/branches/py3k/Objects/floatobject.c	Wed Jun 25 00:28:56 2008
@@ -1113,36 +1113,6 @@
 ">>> (-.25).as_integer_ratio()\n"
 "(-1, 4)");
 
-PyObject *
-_float_to_base(PyObject *v, int base)
-{
-	PyObject *mant, *conv, *result;
-	double x, fr;
-	int i, exp;
-
-	if (!PyFloat_Check(v)) {
-		PyErr_BadInternalCall();
-		return NULL;
-	}
-	CONVERT_TO_DOUBLE(v, x);
-	if (!Py_IS_FINITE(x))
-		return PyObject_Repr(v);
-	fr = frexp(x, &exp);
-	for (i=0; i<300 && fr != floor(fr) ; i++) {
-		fr *= 2.0;
-		exp--;
-	}
-	mant = PyLong_FromDouble(floor(fr));
-	if (mant == NULL)
-		return NULL;
-	conv = PyNumber_ToBase(mant, base);
-	Py_DECREF(mant);
-	if (conv == NULL)
-		return NULL;
-	result = PyUnicode_FromFormat("%U * 2.0 ** %d", conv, exp);
-	Py_DECREF(conv);
-	return result;
-}
 
 static PyObject *
 float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);


More information about the Python-3000-checkins mailing list