summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorRaymond Hettinger <python@rcn.com>2008-06-24 22:46:07 (GMT)
committerRaymond Hettinger <python@rcn.com>2008-06-24 22:46:07 (GMT)
commit9c437af4ebd832d913b85bfb2e666d55565c3665 (patch)
tree993ca8e99a212478a985cdeec1f92892016ce2da /Objects
parent4ac817213bdc9fabd6522754ef6088bac02e74ce (diff)
downloadcpython-9c437af4ebd832d913b85bfb2e666d55565c3665.zip
cpython-9c437af4ebd832d913b85bfb2e666d55565c3665.tar.gz
cpython-9c437af4ebd832d913b85bfb2e666d55565c3665.tar.bz2
Revert 64424, 64438, and 64439.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c72
-rw-r--r--Objects/intobject.c7
-rw-r--r--Objects/longobject.c7
-rw-r--r--Objects/typeobject.c4
4 files changed, 7 insertions, 83 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index f8d1207..32e7cc8 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -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 = {
diff --git a/Objects/intobject.c b/Objects/intobject.c
index 5210ee8..f98aee0 100644
--- a/Objects/intobject.c
+++ b/Objects/intobject.c
@@ -934,12 +934,6 @@ int_float(PyIntObject *v)
}
static PyObject *
-int_bin(PyObject *v)
-{
- return PyNumber_ToBase(v, 2);
-}
-
-static PyObject *
int_oct(PyIntObject *v)
{
return _PyInt_Format(v, 8, 0);
@@ -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 = {
diff --git a/Objects/longobject.c b/Objects/longobject.c
index b603dda..c65d0c0 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3301,12 +3301,6 @@ long_float(PyObject *v)
}
static PyObject *
-long_bin(PyObject *v)
-{
- return PyNumber_ToBase(v, 2);
-}
-
-static PyObject *
long_oct(PyObject *v)
{
return _PyLong_Format(v, 8, 1, 0);
@@ -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 = {
diff --git a/Objects/typeobject.c b/Objects/typeobject.c
index 093fd20..e0ae55b 100644
--- a/Objects/typeobject.c
+++ b/Objects/typeobject.c
@@ -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,