This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Clarifying truncating in documentation
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.11, Python 3.10, Python 3.9
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: docs@python Nosy List: Arthur-Milchior, JelleZijlstra, docs@python, mark.dickinson, miss-islington, python-dev, rhettinger, terry.reedy
Priority: normal Keywords: patch

Created on 2021-10-23 01:31 by Arthur-Milchior, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 29183 merged python-dev, 2021-10-23 01:33
PR 32272 merged miss-islington, 2022-04-02 22:11
PR 32273 merged miss-islington, 2022-04-02 22:12
Messages (9)
msg404850 - (view) Author: Arthur Milchior (Arthur-Milchior) * Date: 2021-10-23 01:31
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)

I assume that I won't be the only user having this trouble, especially for people whose mother tongue is not English. So I suggest adding a clarification to help make what should be obvious to most actually explicit
msg405481 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-11-02 03:18
Current docs:

math.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 Integral value.


math.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 Integral value.


math.trunc(x)
    Return the Real value x truncated to an Integral (usually an integer). Delegates to x.__trunc__().

Problems.
0. First sentence not parallel.
1. What does truncated mean?
2. What does 'Real' mean?
3. Delegation sentence not quite parallel.  Copy the ceil/floor version.

Current Proposal:

 Return the Real value *x* truncated to an Integral (usually an integer). Truncating *x* means removing the digits after the decimal separator, hence rounding toward 0. It is equivalent to floor and ceil for positive and negative numbers respectively.  Delegates to :meth:`x.__trunc__() <object.__trunc__>`.

We can't say "Return the truncation (which refers to the action, not the result).  "Return the truncated remains of x" would be accurate but begs the question about truncate.

I suggest instead:

"Return x with the fractional part removed, leaving the integer part.  This rounds toward 0.0 and is equivalent to floor and ceil for positive and negative x respectively.  If x is not a float, delegates to x.__trunc__(), which should return an Integral value."
msg405483 - (view) Author: Arthur Milchior (Arthur-Milchior) * Date: 2021-11-02 03:28
I'm quite fan of your suggestion. Should I push it on the PR? Do you create another PR? I'm not used to BPO, I beg your pardon, only to github
msg405486 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-11-02 04:07
Yes, revise and retest your branch and push it.
msg405487 - (view) Author: Arthur Milchior (Arthur-Milchior) * Date: 2021-11-02 04:23
Done
msg416598 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-04-02 22:11
New changeset ebbdbbff5d6840807e46ec61b8a323e94ee88de2 by Arthur Milchior in branch 'main':
bpo-45584: Clarify `math.trunc` documentation (GH-29183)
https://github.com/python/cpython/commit/ebbdbbff5d6840807e46ec61b8a323e94ee88de2
msg416599 - (view) Author: Jelle Zijlstra (JelleZijlstra) * (Python committer) Date: 2022-04-02 22:14
Thanks for the patch!
msg416601 - (view) Author: miss-islington (miss-islington) Date: 2022-04-02 22:31
New changeset 3031b867531009d270d5d7d3e53e739c4cba8816 by Miss Islington (bot) in branch '3.10':
bpo-45584: Clarify `math.trunc` documentation (GH-29183)
https://github.com/python/cpython/commit/3031b867531009d270d5d7d3e53e739c4cba8816
msg416602 - (view) Author: miss-islington (miss-islington) Date: 2022-04-02 22:36
New changeset 694425817ba2b3a796acb3413a7111f6de4bd086 by Miss Islington (bot) in branch '3.9':
bpo-45584: Clarify `math.trunc` documentation (GH-29183)
https://github.com/python/cpython/commit/694425817ba2b3a796acb3413a7111f6de4bd086
History
Date User Action Args
2022-04-11 14:59:51adminsetgithub: 89747
2022-04-02 22:36:49miss-islingtonsetmessages: + msg416602
2022-04-02 22:31:16miss-islingtonsetmessages: + msg416601
2022-04-02 22:14:42JelleZijlstrasetstatus: open -> closed
resolution: fixed
messages: + msg416599

stage: patch review -> resolved
2022-04-02 22:12:03miss-islingtonsetpull_requests: + pull_request30336
2022-04-02 22:11:35miss-islingtonsetnosy: + miss-islington
pull_requests: + pull_request30335
2022-04-02 22:11:27JelleZijlstrasetnosy: + JelleZijlstra
messages: + msg416598
2021-11-02 04:23:39Arthur-Milchiorsetmessages: + msg405487
2021-11-02 04:07:54terry.reedysetmessages: + msg405486
2021-11-02 03:28:13Arthur-Milchiorsetmessages: + msg405483
2021-11-02 03:18:09terry.reedysetnosy: + terry.reedy, rhettinger, mark.dickinson

messages: + msg405481
versions: - Python 3.6, Python 3.7, Python 3.8
2021-10-23 01:33:45python-devsetkeywords: + patch
nosy: + python-dev

pull_requests: + pull_request27457
stage: patch review
2021-10-23 01:31:06Arthur-Milchiorcreate