summaryrefslogtreecommitdiffstats
path: root/Modules/_decimal
diff options
context:
space:
mode:
authorMark Dickinson <mdickinson@enthought.com>2012-08-24 17:53:10 (GMT)
committerMark Dickinson <mdickinson@enthought.com>2012-08-24 17:53:10 (GMT)
commitfc33d4ce0a2a89d26c30cd31ccc1992eb495aff0 (patch)
treee4af8aa2446027fb3c8440aedeb4aaa0bc3cda15 /Modules/_decimal
parentcb0ec7dc425bbcd6a3325b2012f6843320219d34 (diff)
downloadcpython-fc33d4ce0a2a89d26c30cd31ccc1992eb495aff0.zip
cpython-fc33d4ce0a2a89d26c30cd31ccc1992eb495aff0.tar.gz
cpython-fc33d4ce0a2a89d26c30cd31ccc1992eb495aff0.tar.bz2
Issue #15544: Fix Decimal.__float__ to work with payload-carrying NaNs.
Diffstat (limited to 'Modules/_decimal')
-rw-r--r--Modules/_decimal/_decimal.c18
1 files changed, 17 insertions, 1 deletions
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index ecca411..15c64e2 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -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;
}