diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2024-11-02 17:11:12 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-11-02 17:11:12 (GMT) |
commit | 7d7d56d8b1147a6b85e1c09d01b164df7c5c4942 (patch) | |
tree | 25dd02e4285b6a7a41b307c3ed7aed654f52155f /Doc/library/string.rst | |
parent | 868bfcc02ed42a1042851830b79c6877b7f1c7a8 (diff) | |
download | cpython-7d7d56d8b1147a6b85e1c09d01b164df7c5c4942.zip cpython-7d7d56d8b1147a6b85e1c09d01b164df7c5c4942.tar.gz cpython-7d7d56d8b1147a6b85e1c09d01b164df7c5c4942.tar.bz2 |
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 <10796600+picnixz@users.noreply.github.com>
---------
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Diffstat (limited to 'Doc/library/string.rst')
-rw-r--r-- | Doc/library/string.rst | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Doc/library/string.rst b/Doc/library/string.rst index 9e8e44a..a000bb4 100644 --- a/Doc/library/string.rst +++ b/Doc/library/string.rst @@ -589,6 +589,11 @@ The available presentation types for :class:`float` and | | as altered by the other format modifiers. | +---------+----------------------------------------------------------+ +The result should be correctly rounded to a given precision ``p`` of digits +after the decimal point. The rounding mode for :class:`float` matches that +of the :func:`round` builtin. For :class:`~decimal.Decimal`, the rounding +mode of the current :ref:`context <decimal-context>` will be used. + The available presentation types for :class:`complex` are the same as those for :class:`float` (``'%'`` is not allowed). Both the real and imaginary components of a complex number are formatted as floating-point numbers, according to the |