mirror of
https://github.com/python/cpython.git
synced 2025-11-25 04:34:37 +00:00
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')).
This commit is contained in:
parent
ff6868cf10
commit
b646757e01
3 changed files with 9 additions and 3 deletions
|
|
@ -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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue