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
Comments
Hi, the following statement yields different results in python2 and python3: In python3 it yields: In python2 it yields: 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. |
In Python 3 "/" gives float division, whereas in Python 2 it is integer division, the same as "//". |
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 |
Does your comment mean that this is bug should be closed as notabug since anyone wanting to avoid such rounding error should use // operator? |
Yes. |
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:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: