Skip to content

Commit a89d703

Browse files
authored
PEP 682: Discussions-To and minor fixes (#2317)
* fill in Discussions-To * fix future references in Rationale * Remove "code-block:: pycon", since it applies a proportional font to '>>>' and '...', which looks odd and misaligns indents. * grammar fix
1 parent c0fc47a commit a89d703

File tree

1 file changed

+13
-23
lines changed

1 file changed

+13
-23
lines changed

pep-0682.rst

+13-23
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@ PEP: 682
22
Title: Format Specifier for Signed Zero
33
Author: John Belmonte <[email protected]>
44
Sponsor: Mark Dickinson <[email protected]>
5-
Discussions-To:
5+
Discussions-To: https://discuss.python.org/t/pep-682-format-specifier-for-signed-zero/13596
66
Status: Draft
77
Type: Standards Track
88
Content-Type: text/x-rst
99
Created: 29-Jan-2022
1010
Python-Version: 3.11
11-
Post-History:
11+
Post-History: 08-Feb-2022
1212

1313

1414
Abstract
@@ -27,9 +27,7 @@ zero to be normalized to positive zero.
2727
Motivation
2828
==========
2929

30-
Here is negative zero:
31-
32-
.. code-block:: pycon
30+
Here is negative zero::
3331

3432
>>> x = -0.
3533
>>> x
@@ -38,9 +36,7 @@ Here is negative zero:
3836
When formatting a number, negative zero can result from rounding. Assuming
3937
the user's intention is truly to discard precision, the distinction between
4038
negative and positive zero of the rounded result might be considered an
41-
unwanted artifact:
42-
43-
.. code-block:: pycon
39+
unwanted artifact::
4440

4541
>>> for x in (.002, -.001, .060):
4642
... print(f'{x: .1f}')
@@ -49,18 +45,14 @@ unwanted artifact:
4945
0.1
5046

5147
There are various approaches to clearing the sign of a negative zero. It
52-
can be achieved without a conditional by adding positive zero:
53-
54-
.. code-block:: pycon
48+
can be achieved without a conditional by adding positive zero::
5549

5650
>>> x = -0.
5751
>>> x + 0.
5852
0.0
5953

6054
To normalize negative zero when formatting, it is necessary to perform
61-
a redundant (and error-prone) pre-rounding of the input:
62-
63-
.. code-block:: pycon
55+
a redundant (and error-prone) pre-rounding of the input::
6456

6557
>>> for x in (.002, -.001, .060):
6658
... print(f'{round(x, 1) + 0.: .1f}')
@@ -112,12 +104,12 @@ one-dimensional numerical arrays would be complicated by such pre-rounding:
112104
"""Format a vector (any iterable) using given per-term format string."""
113105
return f"[{','.join(f'{term:{format_spec}}' for term in v)}]"
114106
115-
To date, there doesn't appear to be other widely-used languages or libraries
116-
providing such a formatting option for negative zero. However, the same
117-
``z`` option syntax and semantics has been `proposed for C++ std::format()`_.
118-
While the proposal was withdrawn for C++20, a consensus proposal is promised
119-
for C++23. (The original `feature request`_ prompting this PEP was argued
120-
without knowledge of the C++ proposal.)
107+
To date, there doesn't appear to be any other widely-used language or library
108+
providing a formatting option for negative zero. However, the same ``z``
109+
option syntax and semantics specified below have been `proposed for C++
110+
std::format()`_. While the proposal was withdrawn for C++20, a consensus
111+
proposal is promised for C++23. (The original `feature request`_ prompting
112+
this PEP was argued without knowledge of the C++ proposal.)
121113

122114
.. _`proposed for C++ std::format()`: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p1496r2.pdf
123115
.. _`feature request`: https://bugs.python.org/issue45995
@@ -138,9 +130,7 @@ where ``z`` is allowed for numerical types other than integer. Support for
138130
allowing the specifier to be used in f-strings, built-in ``format()``, and
139131
``str.format()``. The %-formatting style will not support the new option.
140132

141-
Synopsis:
142-
143-
.. code-block:: pycon
133+
Synopsis::
144134

145135
>>> x = -.00001
146136
>>> f'{x:z.1f}'

0 commit comments

Comments
 (0)