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.

Author mark.dickinson
Recipients Nitin.Kumar, georg.brandl, mark.dickinson
Date 2013-11-14.12:28:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1384432096.54.0.146752218849.issue19446@psf.upfronthosting.co.za>
In-reply-to
Content
Nitin:

> Is there any operator for integer division in python?

Yes, there is: the '//' operator.  :-)

There's no universally agreed upon definition for 'integer division' when negative numbers enter the mix, but I'm guessing that in this case you need something that rounds towards 0 instead of towards -infinity.  There's no dedicated operator for that, but you can simply do (assuming that b is positive):

   -(-a // b) if a < 0 else a // b

References:

[1] http://python-history.blogspot.co.uk/2010/08/why-pythons-integer-division-floors.html
[2] http://docs.python.org/2/faq/programming.html#why-does-22-10-return-3
History
Date User Action Args
2013-11-14 12:28:16mark.dickinsonsetrecipients: + mark.dickinson, georg.brandl, Nitin.Kumar
2013-11-14 12:28:16mark.dickinsonsetmessageid: <1384432096.54.0.146752218849.issue19446@psf.upfronthosting.co.za>
2013-11-14 12:28:16mark.dickinsonlinkissue19446 messages
2013-11-14 12:28:16mark.dickinsoncreate