mirror of
https://github.com/python/cpython.git
synced 2026-04-04 19:13:16 +00:00
#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
This commit is contained in:
parent
672237dc6c
commit
d3ffb8974f
3 changed files with 17 additions and 1 deletions
|
|
@ -1104,6 +1104,13 @@ float_trunc(PyObject *v)
|
|||
return PyLong_FromDouble(wholepart);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
float_long(PyObject *v)
|
||||
{
|
||||
double x = PyFloat_AsDouble(v);
|
||||
return PyLong_FromDouble(x);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
float_float(PyObject *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 */
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue