Issue #5816:
- simplify parsing and printing of complex numbers
- make complex(repr(z)) round-tripping work for complex
numbers involving nans, infs, or negative zeros
- don't accept some of the stranger complex strings
that were previously allowed---e.g., complex('1..1j')
diff --git a/Python/pystrtod.c b/Python/pystrtod.c
index ce2e382..703ae64 100644
--- a/Python/pystrtod.c
+++ b/Python/pystrtod.c
@@ -544,8 +544,9 @@
}
p = result;
- /* Never add sign for nan/inf, even if asked. */
- if (flags & Py_DTSF_SIGN && buf[0] != '-' && t == Py_DTST_FINITE)
+ /* Add sign when requested. It's convenient (esp. when formatting
+ complex numbers) to include a sign even for inf and nan. */
+ if (flags & Py_DTSF_SIGN && buf[0] != '-')
*p++ = '+';
strcpy(p, buf);