summaryrefslogtreecommitdiffstats
path: root/Objects/floatobject.c
diff options
context:
space:
mode:
authorWalter Dörwald <walter@livinglogic.de>2002-11-19 20:49:15 (GMT)
committerWalter Dörwald <walter@livinglogic.de>2002-11-19 20:49:15 (GMT)
commitf171540ab8d816a996c34db3f6aa4bf9cf147fba (patch)
tree001d1ff0bdea449058218d2debf6d6f8dbbcb220 /Objects/floatobject.c
parent7a3bae410df3dd0032509b97077d0c4d98276fdd (diff)
downloadcpython-f171540ab8d816a996c34db3f6aa4bf9cf147fba.zip
cpython-f171540ab8d816a996c34db3f6aa4bf9cf147fba.tar.gz
cpython-f171540ab8d816a996c34db3f6aa4bf9cf147fba.tar.bz2
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
Diffstat (limited to 'Objects/floatobject.c')
-rw-r--r--Objects/floatobject.c20
1 files changed, 9 insertions, 11 deletions
diff --git a/Objects/floatobject.c b/Objects/floatobject.c
index 924b312..129f5bd 100644
--- a/Objects/floatobject.c
+++ b/Objects/floatobject.c
@@ -642,6 +642,13 @@ float_coerce(PyObject **pv, PyObject **pw)
}
static PyObject *
+float_long(PyObject *v)
+{
+ double x = PyFloat_AsDouble(v);
+ return PyLong_FromDouble(x);
+}
+
+static PyObject *
float_int(PyObject *v)
{
double x = PyFloat_AsDouble(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 *