Skip to content

Commit 88c6514

Browse files
belm0AA-Turner
andauthored
PEP 682: small additions (#2322)
Co-authored-by: Adam Turner <9087854+AA-Turner@users.noreply.github.com>
1 parent cc5c674 commit 88c6514

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

pep-0682.rst

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,13 @@ std::format()`_. While the proposal was withdrawn for C++20, a consensus
111111
proposal is promised for C++23. (The original `feature request`_ prompting
112112
this PEP was argued without knowledge of the C++ proposal.)
113113

114+
When Rust developers debated whether to suppress negative zero in ``print``
115+
output, they took a small `survey of other languages`_. Notably, it didn't
116+
mention any language providing an option for negative zero handling.
117+
114118
.. _`proposed for C++ std::format()`: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1496r2.pdf
115119
.. _`feature request`: https://bugs.python.org/issue45995
120+
.. _`survey of other languages`: https://github.com/rust-lang/rfcs/issues/1074#issuecomment-718243936
116121

117122

118123
Specification
@@ -125,7 +130,8 @@ An optional, literal ``z`` is added to the
125130
126131
[[fill]align][sign][z][#][0][width][grouping_option][.precision][type]
127132
128-
where ``z`` is allowed for numerical types other than integer. Support for
133+
where ``z`` is allowed for floating-point presentation types (``f``, ``g``,
134+
etc., as defined by the format specification documentation). Support for
129135
``z`` is provided by the ``.__format__()`` method of each numeric type,
130136
allowing the specifier to be used in f-strings, built-in ``format()``, and
131137
``str.format()``. The %-formatting style will not support the new option.
@@ -159,6 +165,12 @@ the new option, %-formatting cannot. There is already precedent for not
159165
extending %-formatting with new options, as was the case for the
160166
``,`` option (:pep:`378`).
161167

168+
C99 ``printf`` already uses the ``z`` option character for another
169+
purpose: qualifying the unsigned type (``u``) to match the length of
170+
``size_t``. However, since the signed zero option specifically disallows
171+
``z`` for integer presentation types, it's possible to disambiguate the two
172+
uses, should C want to adopt this new option.
173+
162174

163175
Backwards Compatibility
164176
=======================

0 commit comments

Comments
 (0)