Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc: remove a misleading statement. #98093

Merged
merged 1 commit into from Oct 10, 2022

Conversation

JulienPalard
Copy link
Member

@JulienPalard JulienPalard commented Oct 8, 2022

Fixing an issue reported by Alexandr Mezhelovskiy on a moderated message¹ on the docs@ mailing list.

1: the message contained no text body.

The discarding any fractional result part was misleading for negative number, where -7.1 // 1 == -8, as properly explained behind the :term:`floor division` link.

Alexandr proposed to replace the statement with:

floor division returns the minimum integer closest to the quotient

But it's a tutorial and should be kept simple, the goal of this paragraph is just to teach user there's two discting division operators.

For the user in need or more information, the link to the glossary already provides a precise explanation with examples.

@pihie
Copy link

pihie commented Oct 8, 2022

Fixing an issue reported by Alexandr Mezhelovskiy on a moderated message¹ on the docs@ mailing list.

1: the message contained no text body.

The discarding any fractional result part was misleading for negative number, where -7.1 // 1 == -8, as properly explained behind the :term:`floor division` link.

Alexandr proposed to replace the statement with:

floor division returns the minimum integer closest to the quotient

But it's a tutorial and should be kept simple, the goal of this paragraph is just to teach user there's two discting division operators.

For the user in need or more information, the link to the glossary already provides a precise explanation with examples.

Thank you, I saw your commit, but for the sake of concreteness, I suggest adding in parentheses that the result from the division will be rounded down (i guess that sounds simple enough, right?)

@cclauss
Copy link
Contributor

cclauss commented Oct 9, 2022

-7.1 // 1 does not return an int -8 but instead returns a float -8.0

  • python3 -c "print(-7.1 // 1)"

@pihie
Copy link

pihie commented Oct 9, 2022

-7.1 // 1 does not return an int -8 but instead returns a float -8.0

  • python3 -c "print(-7.1 // 1)"

Yes, you’re right, each division returns a float number

@JulienPalard
Copy link
Member Author

JulienPalard commented Oct 10, 2022

-7.1 // 1 does not return an int -8 but instead returns a float -8.0

* `python3 -c "print(-7.1 // 1)"`

TIL about using floats on floor divisions.

Yes, you’re right, each division returns a float number

That's right for / but not // as // is the result of the euclidean division (like % is the rest of the euclidean division) so // often returns an integer, see:

>>> type(-7 // 3) == type(10 // 3) == int
True

I'm puzzeled about // returning an non-integer when given floats, but it's documented in stdtypes.html:

Also referred to as integer division. The resultant value is a whole integer, though the result’s type is not necessarily int. The result is always rounded towards minus infinity: 1//2 is 0, (-1)//2 is -1, 1//(-2) is -1, and (-1)//(-2) is 0.

Clearly not the kind of info I do want to see in the tutorial :D

@JulienPalard JulienPalard merged commit 571e23d into python:main Oct 10, 2022
14 checks passed
@miss-islington
Copy link
Contributor

miss-islington commented Oct 10, 2022

Thanks @JulienPalard for the PR 🌮🎉.. I'm working now to backport this PR to: 3.10, 3.11.
🐍🍒🤖

@JulienPalard JulienPalard deleted the mdk-tutorial-introduction branch Oct 10, 2022
@miss-islington
Copy link
Contributor

miss-islington commented Oct 10, 2022

Sorry @JulienPalard, I had trouble checking out the 3.11 backport branch.
Please backport using cherry_picker on command line.
cherry_picker 571e23d99157ed7ad67ca2334a396fc9ddbe07ec 3.11

@bedevere-bot
Copy link

bedevere-bot commented Oct 10, 2022

GH-98141 is a backport of this pull request to the 3.10 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 10, 2022
(cherry picked from commit 571e23d)

Co-authored-by: Julien Palard <julien@palard.fr>
@miss-islington
Copy link
Contributor

miss-islington commented Oct 10, 2022

Thanks @JulienPalard for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11.
🐍🍒🤖

@bedevere-bot
Copy link

bedevere-bot commented Oct 10, 2022

GH-98142 is a backport of this pull request to the 3.11 branch.

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Oct 10, 2022
(cherry picked from commit 571e23d)

Co-authored-by: Julien Palard <julien@palard.fr>
miss-islington added a commit that referenced this pull request Oct 10, 2022
(cherry picked from commit 571e23d)

Co-authored-by: Julien Palard <julien@palard.fr>
miss-islington added a commit that referenced this pull request Oct 10, 2022
(cherry picked from commit 571e23d)

Co-authored-by: Julien Palard <julien@palard.fr>
mpage pushed a commit to mpage/cpython that referenced this pull request Oct 11, 2022
pablogsal pushed a commit that referenced this pull request Oct 22, 2022
(cherry picked from commit 571e23d)

Co-authored-by: Julien Palard <julien@palard.fr>
Labels
docs Documentation in the Doc dir skip issue skip news
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants