summaryrefslogtreecommitdiffstats
path: root/Doc/library/math.rst
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-04-02 22:30:59 (GMT)
committerGitHub <noreply@github.com>2022-04-02 22:30:59 (GMT)
commit3031b867531009d270d5d7d3e53e739c4cba8816 (patch)
tree9705f3f374e43b4f542befe64a5d4ffe4ee0422c /Doc/library/math.rst
parent8d9a75b206d40b096d9a8f9bcc40d95b7687d6eb (diff)
downloadcpython-3031b867531009d270d5d7d3e53e739c4cba8816.zip
cpython-3031b867531009d270d5d7d3e53e739c4cba8816.tar.gz
cpython-3031b867531009d270d5d7d3e53e739c4cba8816.tar.bz2
bpo-45584: Clarify `math.trunc` documentation (GH-29183)
While floor/ceil 's documentation are very precise, `truncate` was not explained. I actually had to search online to understand the difference between `truncate` and `floor` (admittedly, once I remembered that numbers are signed, and that floating numbers actually uses a bit for negation symbol instead of two complement, it became obvious) Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com> Co-authored-by: Éric Araujo <merwok@netwok.org> Co-authored-by: Terry Jan Reedy <tjreedy@udel.edu> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> (cherry picked from commit ebbdbbff5d6840807e46ec61b8a323e94ee88de2) Co-authored-by: Arthur Milchior <arthur@milchior.fr>
Diffstat (limited to 'Doc/library/math.rst')
-rw-r--r--Doc/library/math.rst18
1 files changed, 10 insertions, 8 deletions
diff --git a/Doc/library/math.rst b/Doc/library/math.rst
index d485ae5..7ba5fa4 100644
--- a/Doc/library/math.rst
+++ b/Doc/library/math.rst
@@ -32,8 +32,8 @@ Number-theoretic and representation functions
.. function:: ceil(x)
Return the ceiling of *x*, the smallest integer greater than or equal to *x*.
- If *x* is not a float, delegates to ``x.__ceil__()``, which should return an
- :class:`~numbers.Integral` value.
+ If *x* is not a float, delegates to :meth:`x.__ceil__ <object.__ceil__>`,
+ which should return an :class:`~numbers.Integral` value.
.. function:: comb(n, k)
@@ -77,9 +77,9 @@ Number-theoretic and representation functions
.. function:: floor(x)
- Return the floor of *x*, the largest integer less than or equal to *x*.
- If *x* is not a float, delegates to ``x.__floor__()``, which should return an
- :class:`~numbers.Integral` value.
+ Return the floor of *x*, the largest integer less than or equal to *x*. If
+ *x* is not a float, delegates to :meth:`x.__floor__ <object.__floor__>`, which
+ should return an :class:`~numbers.Integral` value.
.. function:: fmod(x, y)
@@ -298,9 +298,11 @@ Number-theoretic and representation functions
.. function:: trunc(x)
- Return the :class:`~numbers.Real` value *x* truncated to an
- :class:`~numbers.Integral` (usually an integer). Delegates to
- :meth:`x.__trunc__() <object.__trunc__>`.
+ Return *x* with the fractional part
+ removed, leaving the integer part. This rounds toward 0: ``trunc()`` is
+ equivalent to :func:`floor` for positive *x*, and equivalent to :func:`ceil`
+ for negative *x*. If *x* is not a float, delegates to :meth:`x.__trunc__
+ <object.__trunc__>`, which should return an :class:`~numbers.Integral` value.
.. function:: ulp(x)