summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-09-09 07:24:30 (GMT)
committerAmaury Forgeot d'Arc <amauryfa@gmail.com>2008-09-09 07:24:30 (GMT)
commitd3ffb8974f85618dfbaacf2d10a32dc0e96f2f3d (patch)
tree4eff061ed01ab9ca0ebccb5a61bc8da6972c2ebc /Objects
parent672237dc6ca1498eabac08554bcbc5bd0fd9ddaa (diff)
downloadcpython-d3ffb8974f85618dfbaacf2d10a32dc0e96f2f3d.zip
cpython-d3ffb8974f85618dfbaacf2d10a32dc0e96f2f3d.tar.gz
cpython-d3ffb8974f85618dfbaacf2d10a32dc0e96f2f3d.tar.bz2
#3777: long(4.2) returned an int, and broke backward compatibility.
the __long__ slot is allowed to return either int or long, but the behaviour of float objects should not change between 2.5 and 2.6. Reviewed by Benjamin Peterson
Diffstat (limited to 'Objects')
-rw-r--r--Objects/floatobject.c9
1 files changed, 8 insertions, 1 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 0b067eb..cb38800 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -1105,6 +1105,13 @@ float_trunc(PyObject *v)
}
static PyObject *
+float_long(PyObject *v)
+{
+ double x = PyFloat_AsDouble(v);
+ return PyLong_FromDouble(x);
+}
+
+static PyObject *
float_float(PyObject *v)
{
if (PyFloat_CheckExact(v))
@@ -1897,7 +1904,7 @@ static PyNumberMethods float_as_number = {
0, /*nb_or*/
float_coerce, /*nb_coerce*/
float_trunc, /*nb_int*/
- float_trunc, /*nb_long*/
+ float_long, /*nb_long*/
float_float, /*nb_float*/
0, /* nb_oct */
0, /* nb_hex */