mirror of
https://github.com/python/cpython.git
synced 2025-07-28 13:44:43 +00: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:
parent
508c423fe1
commit
95bc980d9e
4 changed files with 233 additions and 179 deletions
|
@ -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);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue