mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
This commit is contained in:
parent
cb0ec7dc42
commit
fc33d4ce0a
4 changed files with 42 additions and 2 deletions
|
@ -3357,7 +3357,23 @@ PyDec_AsFloat(PyObject *dec)
|
|||
{
|
||||
PyObject *f, *s;
|
||||
|
||||
s = dec_str(dec);
|
||||
if (mpd_isnan(MPD(dec))) {
|
||||
if (mpd_issnan(MPD(dec))) {
|
||||
PyErr_SetString(PyExc_ValueError,
|
||||
"cannot convert signaling NaN to float");
|
||||
return NULL;
|
||||
}
|
||||
if (mpd_isnegative(MPD(dec))) {
|
||||
s = PyUnicode_FromString("-nan");
|
||||
}
|
||||
else {
|
||||
s = PyUnicode_FromString("nan");
|
||||
}
|
||||
}
|
||||
else {
|
||||
s = dec_str(dec);
|
||||
}
|
||||
|
||||
if (s == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue