Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.

This commit is contained in:
Mark Dickinson 2012-08-24 18:53:10 +01:00
parent cb0ec7dc42
commit fc33d4ce0a
4 changed files with 42 additions and 2 deletions

View file

@ -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;
}