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

Integer division numerical error #87282

Closed
jfu334 mannequin opened this issue Feb 3, 2021 · 2 comments
Closed

Integer division numerical error #87282

jfu334 mannequin opened this issue Feb 3, 2021 · 2 comments
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@jfu334
Copy link
Mannequin

jfu334 mannequin commented Feb 3, 2021

BPO 43116
Nosy @mdickinson

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-02-03.14:03:28.166>
created_at = <Date 2021-02-03.13:49:36.044>
labels = ['3.8', 'type-bug', '3.7', '3.9', 'invalid']
title = 'Integer division numerical error'
updated_at = <Date 2021-02-03.14:03:28.165>
user = 'https://bugs.python.org/jfu334'

bugs.python.org fields:

activity = <Date 2021-02-03.14:03:28.165>
actor = 'mark.dickinson'
assignee = 'none'
closed = True
closed_date = <Date 2021-02-03.14:03:28.166>
closer = 'mark.dickinson'
components = []
creation = <Date 2021-02-03.13:49:36.044>
creator = 'jfu33.4'
dependencies = []
files = []
hgrepos = []
issue_num = 43116
keywords = []
message_count = 2.0
messages = ['386204', '386208']
nosy_count = 2.0
nosy_names = ['mark.dickinson', 'jfu33.4']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue43116'
versions = ['Python 3.7', 'Python 3.8', 'Python 3.9']

@jfu334
Copy link
Mannequin Author

jfu334 mannequin commented Feb 3, 2021

I'm a bit confused because this seems to be too obvious to be a bug:

[code]
>>> -2094820900 // 1298
-1613884
>>> -2094820900 // -1298
1613883
[/code]

Obviously there is a +/- 1 difference in the result.

Tested with Python 3.7, 3.8 and 3.9 on Debian Bullseye. Am I missing something?

@jfu334 jfu334 mannequin added 3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Feb 3, 2021
@mdickinson
Copy link
Member

Python's // operator does floor division: that is, the (true) quotient is converted to an integer by taking the floor (rounding towards -infinity) instead of truncating (rounding towards zero).

So indeed it's not a bug. The behaviour is documented here: https://docs.python.org/3/reference/expressions.html#binary-arithmetic-operations

See also bpo-43034

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.7 (EOL) end of life 3.8 only security fixes 3.9 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

1 participant