diff options
author | Mark Dickinson <dickinsm@gmail.com> | 2008-08-04 21:30:09 (GMT) |
---|---|---|
committer | Mark Dickinson <dickinsm@gmail.com> | 2008-08-04 21:30:09 (GMT) |
commit | b646757e01d51c242eef2f9802f1ca6836a5804a (patch) | |
tree | f0976c5dcec20fa8bf42db406006df4058e394a1 /Objects | |
parent | ff6868cf10409441666d462af7df6a04faa45d1c (diff) | |
download | cpython-b646757e01d51c242eef2f9802f1ca6836a5804a.zip cpython-b646757e01d51c242eef2f9802f1ca6836a5804a.tar.gz cpython-b646757e01d51c242eef2f9802f1ca6836a5804a.tar.bz2 |
Issue #1481296: (again!) Make conversion of a float NaN to an int or
long raise ValueError instead of returning 0. Also, change the error
message for conversion of an infinity to an integer, replacing 'long' by
'integer', so that it's appropriate for both long(float('inf')) and
int(float('inf')).
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/longobject.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 228376a..6513069 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -176,11 +176,13 @@ PyLong_FromDouble(double dval) neg = 0; if (Py_IS_INFINITY(dval)) { PyErr_SetString(PyExc_OverflowError, - "cannot convert float infinity to long"); + "cannot convert float infinity to integer"); return NULL; } if (Py_IS_NAN(dval)) { - return PyLong_FromLong(0L); + PyErr_SetString(PyExc_ValueError, + "cannot convert float NaN to integer"); + return NULL; } if (dval < 0.0) { neg = 1; |