Change int() so that passing a string, unicode, float or long argument

that is outside the integer range no longer raises OverflowError, but
returns a long object instead.

This fixes SF bug http://www.python.org/sf/635115
This commit is contained in:
Walter Dörwald 2002-11-19 20:49:15 +00:00
parent 7a3bae410d
commit f171540ab8
9 changed files with 82 additions and 49 deletions

View file

@ -641,6 +641,13 @@ float_coerce(PyObject **pv, PyObject **pw)
return 1; /* Can't do it */
}
static PyObject *
float_long(PyObject *v)
{
double x = PyFloat_AsDouble(v);
return PyLong_FromDouble(x);
}
static PyObject *
float_int(PyObject *v)
{
@ -652,8 +659,7 @@ float_int(PyObject *v)
#ifdef RISCOS
/* conversion from floating to integral type would raise exception */
if (wholepart>LONG_MAX || wholepart<LONG_MIN) {
PyErr_SetString(PyExc_OverflowError, "float too large to convert");
return NULL;
return float_long(v);
}
#endif
/* doubles may have more bits than longs, or vice versa; and casting
@ -663,15 +669,7 @@ float_int(PyObject *v)
aslong = (long)wholepart;
if ((double)aslong == wholepart)
return PyInt_FromLong(aslong);
PyErr_SetString(PyExc_OverflowError, "float too large to convert");
return NULL;
}
static PyObject *
float_long(PyObject *v)
{
double x = PyFloat_AsDouble(v);
return PyLong_FromDouble(x);
return float_long(v);
}
static PyObject *