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

Different division results with / and // operators with large numbers #62021

Closed
PhilippeRouquier mannequin opened this issue Apr 23, 2013 · 5 comments
Closed

Different division results with / and // operators with large numbers #62021

PhilippeRouquier mannequin opened this issue Apr 23, 2013 · 5 comments
Labels
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@PhilippeRouquier
Copy link
Mannequin

PhilippeRouquier mannequin commented Apr 23, 2013

BPO 17821
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 2013-04-23.11:47:14.010>
created_at = <Date 2013-04-23.09:19:59.016>
labels = ['interpreter-core', 'type-bug', 'invalid']
title = 'Different division results with / and // operators with large numbers'
updated_at = <Date 2013-04-23.11:47:14.006>
user = 'https://bugs.python.org/PhilippeRouquier'

bugs.python.org fields:

activity = <Date 2013-04-23.11:47:14.006>
actor = 'sbt'
assignee = 'none'
closed = True
closed_date = <Date 2013-04-23.11:47:14.010>
closer = 'sbt'
components = ['Interpreter Core']
creation = <Date 2013-04-23.09:19:59.016>
creator = 'Philippe.Rouquier'
dependencies = []
files = []
hgrepos = []
issue_num = 17821
keywords = []
message_count = 5.0
messages = ['187623', '187624', '187625', '187626', '187628']
nosy_count = 3.0
nosy_names = ['mark.dickinson', 'sbt', 'Philippe.Rouquier']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue17821'
versions = ['Python 3.3']

@PhilippeRouquier
Copy link
Mannequin Author

PhilippeRouquier mannequin commented Apr 23, 2013

Hi,

the following statement yields different results in python2 and python3:
284397269195572115652769428988866694680//17 - int(284397269195572115652769428988866694680/17)

In python3 it yields:
309657313492949847071

In python2 it yields:
OL

Python2's result seems to be correct as (284397269195572115652769428988866694680//17) and (int(284397269195572115652769428988866694680/17)) should return the same result (as far as I understand).

With smaller numbers, this difference in results does not appear with python3.

Note: I noticed this, while working on RSA; 284397269195572115652769428988866694680 is (p-1)(q-1) and 17 is e. I just mention this in case it could help.

I used linux version 3.3.3.0 and 2.7.3 for the tests on a 64 bits processor.

Sorry if I am missing something here.

@PhilippeRouquier PhilippeRouquier mannequin added interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error labels Apr 23, 2013
@sbt
Copy link
Mannequin

sbt mannequin commented Apr 23, 2013

In Python 3 "/" gives float division, whereas in Python 2 it is integer division, the same as "//".

@sbt
Copy link
Mannequin

sbt mannequin commented Apr 23, 2013

Just to clarify, if you use float division then you get rounding errors. 309657313492949847071 is a rounding error:

>>> x = 284397269195572115652769428988866694680//17
>>> x - int(float(x))
309657313492949847071L

@PhilippeRouquier
Copy link
Mannequin Author

PhilippeRouquier mannequin commented Apr 23, 2013

Does your comment mean that this is bug should be closed as notabug since anyone wanting to avoid such rounding error should use // operator?

@sbt
Copy link
Mannequin

sbt mannequin commented Apr 23, 2013

Yes.

@sbt sbt mannequin closed this as completed Apr 23, 2013
@sbt sbt mannequin added the invalid label Apr 23, 2013
@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
interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

0 participants