Skip to content

Commit ebbdbbf

Browse files
Arthur-MilchiorAlexWaygoodmerwokterryjreedyJelleZijlstra
authored
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 <[email protected]> Co-authored-by: Éric Araujo <[email protected]> Co-authored-by: Terry Jan Reedy <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]>
1 parent 1f80dcd commit ebbdbbf

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

Doc/library/math.rst

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ Number-theoretic and representation functions
3232
.. function:: ceil(x)
3333

3434
Return the ceiling of *x*, the smallest integer greater than or equal to *x*.
35-
If *x* is not a float, delegates to ``x.__ceil__()``, which should return an
36-
:class:`~numbers.Integral` value.
35+
If *x* is not a float, delegates to :meth:`x.__ceil__ <object.__ceil__>`,
36+
which should return an :class:`~numbers.Integral` value.
3737

3838

3939
.. function:: comb(n, k)
@@ -77,9 +77,9 @@ Number-theoretic and representation functions
7777

7878
.. function:: floor(x)
7979

80-
Return the floor of *x*, the largest integer less than or equal to *x*.
81-
If *x* is not a float, delegates to ``x.__floor__()``, which should return an
82-
:class:`~numbers.Integral` value.
80+
Return the floor of *x*, the largest integer less than or equal to *x*. If
81+
*x* is not a float, delegates to :meth:`x.__floor__ <object.__floor__>`, which
82+
should return an :class:`~numbers.Integral` value.
8383

8484

8585
.. function:: fmod(x, y)
@@ -298,9 +298,11 @@ Number-theoretic and representation functions
298298

299299
.. function:: trunc(x)
300300

301-
Return the :class:`~numbers.Real` value *x* truncated to an
302-
:class:`~numbers.Integral` (usually an integer). Delegates to
303-
:meth:`x.__trunc__() <object.__trunc__>`.
301+
Return *x* with the fractional part
302+
removed, leaving the integer part. This rounds toward 0: ``trunc()`` is
303+
equivalent to :func:`floor` for positive *x*, and equivalent to :func:`ceil`
304+
for negative *x*. If *x* is not a float, delegates to :meth:`x.__trunc__
305+
<object.__trunc__>`, which should return an :class:`~numbers.Integral` value.
304306

305307
.. function:: ulp(x)
306308

0 commit comments

Comments
 (0)