]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Revert 64424, 64438, and 64439.
authorRaymond Hettinger <python@rcn.com>
Tue, 24 Jun 2008 22:46:07 +0000 (22:46 +0000)
committerRaymond Hettinger <python@rcn.com>
Tue, 24 Jun 2008 22:46:07 +0000 (22:46 +0000)
Include/object.h
Lib/test/test_builtin.py
Lib/test/test_sys.py
Misc/NEWS
Objects/floatobject.c
Objects/intobject.c
Objects/longobject.c
Objects/typeobject.c
Python/bltinmodule.c

index 709174fdf5b55c2d7b0c36488821082e4d3066db..59f3b9e1b100c6815585243d3112ae25c3277115 100644 (file)
@@ -267,9 +267,6 @@ typedef struct {
 
        /* Added in release 2.5 */
        unaryfunc nb_index;
-
-       /* Added in release 2.6 */
-       unaryfunc nb_bin;
 } PyNumberMethods;
 
 typedef struct {
index 8c46ab8eb3f94b6a17b232a2105289413677cc69..15d80a369831dc35a384844e57d94410a1e426d8 100644 (file)
@@ -631,15 +631,6 @@ class BuiltinTest(unittest.TestCase):
         self.assertEqual(hex(-16), '-0x10')
         self.assertEqual(hex(-16L), '-0x10L')
         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)
@@ -923,15 +914,6 @@ class BuiltinTest(unittest.TestCase):
         self.assertEqual(oct(-100), '-0144')
         self.assertEqual(oct(-100L), '-0144L')
         self.assertRaises(TypeError, oct, ())
-        self.assertEqual(oct(3.125), '031 * 2.0 ** -3')
-        self.assertEqual(oct(0.0), '0 * 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 and raw_input, below
@@ -1484,15 +1466,6 @@ class BuiltinTest(unittest.TestCase):
         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):
 
index c98117ac5b61ba90b9448b550c9ce1f240a9e5fc..f1fb61549e24da6faac5fcab3528cdb193d39827 100644 (file)
@@ -523,7 +523,7 @@ class SizeofTest(unittest.TestCase):
         len_typeobject = p + 2*l + 15*p + l + 4*p + l + 9*p +\
                          l + 11*p + self.align(4)
         self.check_sizeof(class_newstyle,
-                          h + len_typeobject + 42*p + 10*p + 3*p + 6*p)
+                          h + len_typeobject + 41*p + 10*p + 3*p + 6*p)
 
     def test_specialtypes(self):
         i = self.i
index 022196f3d702a14b9407256bc182cd5914da9229..e91b6962e48ce3d23866165544ef2759eb2f25e3 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -17,12 +17,6 @@ Core and Builtins
   slice(None, 10, -1).indices(10) returns (9, 9, -1) instead of (9,
   10, -1).
 
-- Issue 3008: hex(), oct(), and bin() can now create exact reprs 
-  for floats.
-
-- Make bin() implementation parallel oct() and hex().
-
-
 What's New in Python 2.6 beta 1?
 ================================
 
index f8d1207b83f83131c955b94677421c2cd7e1d16c..32e7cc8088cec0e9d961c46584719145f68239b8 100644 (file)
@@ -405,11 +405,11 @@ PyFloat_AsStringEx(char *buf, PyFloatObject *v, int precision)
    obj is not of float, int or long type, Py_NotImplemented is incref'ed,
    stored in obj, and returned from the function invoking this macro.
 */
-#define CONVERT_TO_DOUBLE(obj, dbl)                                    \
-       if (PyFloat_Check(obj))                                         \
-               dbl = PyFloat_AS_DOUBLE(obj);                           \
-       else if (convert_to_double((PyObject **)&(obj), &(dbl)) < 0)    \
-               return (PyObject *)(obj);
+#define CONVERT_TO_DOUBLE(obj, dbl)                    \
+       if (PyFloat_Check(obj))                         \
+               dbl = PyFloat_AS_DOUBLE(obj);           \
+       else if (convert_to_double(&(obj), &(dbl)) < 0) \
+               return obj;
 
 static int
 convert_to_double(PyObject **v, double *dbl)
@@ -1204,62 +1204,6 @@ PyDoc_STRVAR(float_as_integer_ratio_doc,
 ">>> (-.25).as_integer_ratio()\n"
 "(-1, 4)");
 
-static PyObject *
-_float_to_base(PyFloatObject *v, unaryfunc int_to_base)
-{
-       PyObject *mant, *conv, *result;
-       double x, fr;
-       int i, exp, n;
-       char *conv_str;
-
-       CONVERT_TO_DOUBLE(v, x);
-       if (!Py_IS_FINITE(x))
-               return PyObject_Repr((PyObject *)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 = int_to_base(mant);
-       Py_DECREF(mant);
-       if (conv== NULL)
-               return NULL;
-       n = PyString_GET_SIZE(conv);
-       conv_str = PyString_AS_STRING(conv);
-       /* Remove the trailing 'L' if present */
-       if (n && conv_str[n-1] == 'L') {
-               PyObject *newconv = PySequence_GetSlice(conv, 0, -1);
-               Py_DECREF(conv);
-               if (newconv == NULL)
-                       return NULL;
-               conv = newconv;
-               conv_str = PyString_AS_STRING(conv);
-       }
-       result = PyString_FromFormat("%s * 2.0 ** %d", conv_str, exp);
-       Py_DECREF(conv);
-       return result;
-}
-
-static PyObject *
-float_hex(PyFloatObject *v)
-{
-       return _float_to_base(v, PyLong_Type.tp_as_number->nb_hex);
-}
-
-static PyObject *
-float_oct(PyFloatObject *v)
-{
-       return _float_to_base(v, PyLong_Type.tp_as_number->nb_oct);
-}
-
-static PyObject *
-float_bin(PyFloatObject *v)
-{
-       return _float_to_base(v, PyLong_Type.tp_as_number->nb_bin);
-}
 
 static PyObject *
 float_subtype_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
@@ -1546,8 +1490,8 @@ static PyNumberMethods float_as_number = {
        float_trunc,    /*nb_int*/
        float_trunc,    /*nb_long*/
        float_float,    /*nb_float*/
-       (unaryfunc)float_oct,           /* nb_oct */
-       (unaryfunc)float_hex,           /* nb_hex */
+       0,              /* nb_oct */
+       0,              /* nb_hex */
        0,              /* nb_inplace_add */
        0,              /* nb_inplace_subtract */
        0,              /* nb_inplace_multiply */
@@ -1563,8 +1507,6 @@ static PyNumberMethods float_as_number = {
        float_div,      /* nb_true_divide */
        0,              /* nb_inplace_floor_divide */
        0,              /* nb_inplace_true_divide */
-       0,              /* nb_index */
-       (unaryfunc)float_bin,           /* nb_bin */
 };
 
 PyTypeObject PyFloat_Type = {
index 5210ee8db7ce545e6feede0ddbf0618cad5e45e9..f98aee0e2e1544d1e59cbfc3ab5b1c8a8a7216db 100644 (file)
@@ -933,12 +933,6 @@ int_float(PyIntObject *v)
        return PyFloat_FromDouble((double)(v -> ob_ival));
 }
 
-static PyObject *
-int_bin(PyObject *v)
-{
-        return PyNumber_ToBase(v, 2);
-}
-
 static PyObject *
 int_oct(PyIntObject *v)
 {
@@ -1237,7 +1231,6 @@ static PyNumberMethods int_as_number = {
        0,                      /* nb_inplace_floor_divide */
        0,                      /* nb_inplace_true_divide */
        (unaryfunc)int_int,     /* nb_index */
-       (unaryfunc)int_bin,     /* nb_bin */
 };
 
 PyTypeObject PyInt_Type = {
index b603dda269f44f7e78aaf1553accf0c4084ed9c5..c65d0c00abe8037ea85552d941dcb7414d2bb726 100644 (file)
@@ -3300,12 +3300,6 @@ long_float(PyObject *v)
        return PyFloat_FromDouble(result);
 }
 
-static PyObject *
-long_bin(PyObject *v)
-{
-        return PyNumber_ToBase(v, 2);
-}
-
 static PyObject *
 long_oct(PyObject *v)
 {
@@ -3546,7 +3540,6 @@ static PyNumberMethods long_as_number = {
        0,                              /* nb_inplace_floor_divide */
        0,                              /* nb_inplace_true_divide */
        long_long,                      /* nb_index */
-       long_bin,                       /* nb_bin */
 };
 
 PyTypeObject PyLong_Type = {
index 093fd20a82880b502ca471fc8441e3355ef56a7f..e0ae55b057ca92038351e36eba9e4f50479bc55f 100644 (file)
@@ -3743,7 +3743,6 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base)
                if (base->tp_flags & Py_TPFLAGS_HAVE_INDEX) {
                        COPYNUM(nb_index);
                }
-               COPYNUM(nb_hex);
        }
 
        if (type->tp_as_sequence != NULL && base->tp_as_sequence != NULL) {
@@ -5136,7 +5135,6 @@ slot_nb_coerce(PyObject **a, PyObject **b)
 SLOT0(slot_nb_int, "__int__")
 SLOT0(slot_nb_long, "__long__")
 SLOT0(slot_nb_float, "__float__")
-SLOT0(slot_nb_bin, "__bin__")
 SLOT0(slot_nb_oct, "__oct__")
 SLOT0(slot_nb_hex, "__hex__")
 SLOT1(slot_nb_inplace_add, "__iadd__", PyObject *, "O")
@@ -5804,8 +5802,6 @@ static slotdef slotdefs[] = {
               "long(x)"),
        UNSLOT("__float__", nb_float, slot_nb_float, wrap_unaryfunc,
               "float(x)"),
-       UNSLOT("__bin__", nb_bin, slot_nb_bin, wrap_unaryfunc,
-              "bin(x)"),
        UNSLOT("__oct__", nb_oct, slot_nb_oct, wrap_unaryfunc,
               "oct(x)"),
        UNSLOT("__hex__", nb_hex, slot_nb_hex, wrap_unaryfunc,
index 7647523b580feca999f76aa72453e1460443eb55..e18eb2a95a90ac356af65d8ae295cbcf9bb77cbd 100644 (file)
@@ -211,24 +211,7 @@ Deprecated since release 2.3. Instead, use the extended call syntax:\n\
 static PyObject *
 builtin_bin(PyObject *self, PyObject *v)
 {
-       PyNumberMethods *nb;
-       PyObject *res;
-
-       if ((nb = v->ob_type->tp_as_number) == NULL ||
-           nb->nb_hex == NULL) {
-               PyErr_SetString(PyExc_TypeError,
-                          "bin() argument can't be converted to hex");
-               return NULL;
-       }
-       res = (*nb->nb_bin)(v);
-       if (res && !PyString_Check(res)) {
-               PyErr_Format(PyExc_TypeError,
-                            "__bin__ returned non-string (type %.200s)",
-                            res->ob_type->tp_name);
-               Py_DECREF(res);
-               return NULL;
-       }
-       return res;
+        return PyNumber_ToBase(v, 2);
 }
 
 PyDoc_STRVAR(bin_doc,