Skip to content

Commit 7d7d56d

Browse files
skirpichevpicnixz
andauthored
gh-99880: document rounding mode for new-style formatting (GH-121481)
* gh-99880: document rounding mode for new-style formatting The CPython uses _Py_dg_dtoa(), which does rounding to nearest with half to even tie-breaking rule. If that functions is unavailable, PyOS_double_to_string() fallbacks to system snprintf(). Since CPython 3.12, build requirements include C11 compiler *and* support for IEEE 754 floating point numbers (Annex F). This means that FE_TONEAREST macro is available and, per default, printf-like functions should use same rounding mode as _Py_dg_dtoa(). * Update Doc/library/string.rst Co-authored-by: Bénédikt Tran <[email protected]> --------- Co-authored-by: Bénédikt Tran <[email protected]>
1 parent 868bfcc commit 7d7d56d

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

Doc/library/string.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -589,6 +589,11 @@ The available presentation types for :class:`float` and
589589
| | as altered by the other format modifiers. |
590590
+---------+----------------------------------------------------------+
591591

592+
The result should be correctly rounded to a given precision ``p`` of digits
593+
after the decimal point. The rounding mode for :class:`float` matches that
594+
of the :func:`round` builtin. For :class:`~decimal.Decimal`, the rounding
595+
mode of the current :ref:`context <decimal-context>` will be used.
596+
592597
The available presentation types for :class:`complex` are the same as those for
593598
:class:`float` (``'%'`` is not allowed). Both the real and imaginary components
594599
of a complex number are formatted as floating-point numbers, according to the

0 commit comments

Comments
 (0)