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

7/200 and 7%200 show weird results #54372

Closed
HenryEshbaugh mannequin opened this issue Oct 21, 2010 · 5 comments
Closed

7/200 and 7%200 show weird results #54372

HenryEshbaugh mannequin opened this issue Oct 21, 2010 · 5 comments

Comments

@HenryEshbaugh
Copy link
Mannequin

HenryEshbaugh mannequin commented Oct 21, 2010

BPO 10163
Nosy @birkenfeld, @mdickinson, @ericvsmith

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 2010-10-21.14:11:56.078>
created_at = <Date 2010-10-21.11:21:47.861>
labels = ['invalid']
title = '7/200 and 7%200 show weird results'
updated_at = <Date 2010-10-21.14:11:56.077>
user = 'https://bugs.python.org/HenryEshbaugh'

bugs.python.org fields:

activity = <Date 2010-10-21.14:11:56.077>
actor = 'georg.brandl'
assignee = 'none'
closed = True
closed_date = <Date 2010-10-21.14:11:56.078>
closer = 'georg.brandl'
components = []
creation = <Date 2010-10-21.11:21:47.861>
creator = 'Henry.Eshbaugh'
dependencies = []
files = []
hgrepos = []
issue_num = 10163
keywords = []
message_count = 5.0
messages = ['119274', '119275', '119279', '119299', '119300']
nosy_count = 4.0
nosy_names = ['georg.brandl', 'mark.dickinson', 'eric.smith', 'Henry.Eshbaugh']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue10163'
versions = []

@HenryEshbaugh
Copy link
Mannequin Author

HenryEshbaugh mannequin commented Oct 21, 2010

This may be happening with other numbers, but I got weird results with the modulus and division operators, after I imported the math module. I tried to do 7/200 and got 0, and 200%7 yielded 7, an impossibility with modulus.

@birkenfeld
Copy link
Member

The result of 7 / 200 is easy to explain -- this is how integer division works in Python 2. (To get a floating result, one of the numbers must be a float.)

200 % 7 giving 7 however is strange. Are you sure this is what you calculated?

@ericvsmith
Copy link
Member

Which version of python? Could you run this from the command line and paste the complete session, including the version info that python prints on startup?

@mdickinson
Copy link
Member

Seconding Eric's comment. This is what I get on my machine; can you cut and paste the equivalent output on yours (including whatever else is required to reproduce the results you describe)

Python 2.6.1 (r261:67515, Feb 11 2010, 15:47:53) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 200 % 7
4

In any case, please let us know which version of Python you're using, and where you got it from.

@birkenfeld
Copy link
Member

The bug title interestingly says "7%200", which does result in 7. I therefore think the OP just confused the order of operands for "%".

@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
None yet
Projects
None yet
Development

No branches or pull requests

3 participants