This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Different division results with / and // operators with large numbers
Type: behavior Stage: resolved
Components: Interpreter Core Versions: Python 3.3
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Philippe.Rouquier, mark.dickinson, sbt
Priority: normal Keywords:

Created on 2013-04-23 09:19 by Philippe.Rouquier, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg187623 - (view) Author: Philippe Rouquier (Philippe.Rouquier) Date: 2013-04-23 09:19
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.
msg187624 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-04-23 09:55
In Python 3 "/" gives float division, whereas in Python 2 it is integer division, the same as "//".
msg187625 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-04-23 10:01
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
msg187626 - (view) Author: Philippe Rouquier (Philippe.Rouquier) Date: 2013-04-23 11:26
Does your comment mean that this is bug should be closed as notabug since anyone wanting to avoid such rounding error should use // operator?
msg187628 - (view) Author: Richard Oudkerk (sbt) * (Python committer) Date: 2013-04-23 11:47
Yes.
History
Date User Action Args
2022-04-11 14:57:44adminsetgithub: 62021
2013-04-23 11:47:14sbtsetstatus: open -> closed
resolution: not a bug
messages: + msg187628

stage: resolved
2013-04-23 11:26:02Philippe.Rouquiersetmessages: + msg187626
2013-04-23 10:01:33sbtsetmessages: + msg187625
2013-04-23 09:55:58sbtsetnosy: + sbt
messages: + msg187624
2013-04-23 09:25:08ezio.melottisetnosy: + mark.dickinson
2013-04-23 09:19:59Philippe.Rouquiercreate