bpo-45995: add "z" format specifer to coerce negative 0 to zero (GH-30049)

Add "z" format specifier to coerce negative 0 to zero.

See https://github.com/python/cpython/issues/90153 (originally https://bugs.python.org/issue45995) for discussion.
This covers `str.format()` and f-strings.  Old-style string interpolation is not supported.

Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
John Belmonte 2022-04-11 23:34:18 +09:00 committed by GitHub
parent dd207a6ac5
commit b0b836b20c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
16 changed files with 368 additions and 43 deletions

View file

@ -6119,7 +6119,7 @@ topics = {'assert': 'The "assert" statement\n'
'The general form of a *standard format specifier* is:\n'
'\n'
' format_spec ::= '
'[[fill]align][sign][#][0][width][grouping_option][.precision][type]\n'
'[[fill]align][sign][z][#][0][width][grouping_option][.precision][type]\n'
' fill ::= <any character>\n'
' align ::= "<" | ">" | "=" | "^"\n'
' sign ::= "+" | "-" | " "\n'
@ -6221,6 +6221,15 @@ topics = {'assert': 'The "assert" statement\n'
' '
'+-----------+------------------------------------------------------------+\n'
'\n'
'The "\'z\'" option coerces negative zero floating-point '
'values to positive\n'
'zero after rounding to the format precision. This option '
'is only valid for\n'
'floating-point presentation types.\n'
'\n'
'Changed in version 3.11: Added the "\'z\'" option (see also '
'**PEP 682**).\n'
'\n'
'The "\'#\'" option causes the “alternate form” to be used '
'for the\n'
'conversion. The alternate form is defined differently for '