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: Negative integer division error
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: Integer division for negative numbers
View: 19446
Assigned To: Nosy List: mark.dickinson, r.david.murray, vatroslavsuton
Priority: normal Keywords:

Created on 2013-11-13 21:01 by vatroslavsuton, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (3)
msg202778 - (view) Author: Vatroslav Suton (vatroslavsuton) Date: 2013-11-13 21:01
integer division obviously uses float division with math.floor, which produces invalid result when result is less than 0, simply try the following 5/2 versus -5/2. Please use math.ceil function for results less than 0.
btw is there any way to patch that in __builtins__ ?
msg202782 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2013-11-13 21:34
This is not an aspect of Python that can possibly change, I'm afraid, for backward compatibility reasons.
msg202784 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2013-11-13 21:38
See also http://docs.python.org/2/faq/programming.html#why-does-22-10-return-3

BTW, integer division does not use float division internally.  That would fail for integers too large to be exactly representable as floats.  The implementation can be seen in Objects/intobject.c and Objects/longobject.c if you're interested.
History
Date User Action Args
2022-04-11 14:57:53adminsetgithub: 63773
2013-11-13 21:38:21mark.dickinsonsetnosy: + mark.dickinson
messages: + msg202784
2013-11-13 21:34:50r.david.murraysetstatus: open -> closed

superseder: Integer division for negative numbers

nosy: + r.david.murray
messages: + msg202782
resolution: duplicate
stage: resolved
2013-11-13 21:01:28vatroslavsutoncreate