mirror of
https://github.com/python/cpython.git
synced 2026-05-22 04:13:22 -04:00
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')
This commit is contained in:
+3
-2
@@ -544,8 +544,9 @@ PyAPI_FUNC(char *) PyOS_double_to_string(double val,
|
||||
}
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user